Page 1 of 1

Windows File Date Time Attributes

Posted: Thu Jan 06, 2005 3:23 am
by ianm
How can I get the Date and Time Attributes of a Windows file ?

Posted: Thu Jan 06, 2005 3:38 am
by ArndW
I usually cheat and do a DOS shell command of "DIR" (or UNIX "ls -alk")and manually parse the resultant output string. You can wrap up that logic into a routine if you wish. The method to use depends upon where in DataStage you want to use the time & date attributes.

Posted: Thu Jan 06, 2005 5:09 am
by nkln@you
ArnDW , can u pls elaborate on how to execute this dos statement in DataStage.

Posted: Thu Jan 06, 2005 5:34 am
by ArndW
nlkn - I have attached some sample code to do this. You will need to add some error checking and might need to change the format around depending upon your system's locale settings.

Code: Select all

Rem **************************************************************************************
Rem ** Routine to return the Date & Time of a DOS file as format "DD-MM-YYYY HH:MM:SS"  **
Rem ** The single lines of the program can be combined for efficiency, they have been   **
Rem ** separated for clarity. The date format that is output by dos is installation     **
Rem ** dependant, on my system it displays as MDY but that changes according to Windows **
Rem ** locale settings.                                                                 **
Rem ** Routine input parameter is "FileName" and needs the fully qualified DOS pathname **
Rem ** to the file.                                                                     **
Rem **************************************************************************************
CALL DSExecute("NT","DIR ":FileName,StringOutput,ErrorCode) ;** Get the DOS info
TempString = TRIM(StringOutput<6>)                          ;** the 6th line has the details
WorkDate   = ICONV(FIELD(TempString," ",1),"D4/MDY")        ;** convert date to internal fmt
WorkTime   = ICONV(FIELD(TempString," ",2),"MTS")           ;** convert time to internal fmt
Ans        = OCONV(WorkDate,"D4-DMY[2,2,4]")                ;** Create output date part of string
Ans        := " ":OCONV(WorkTime,"MTS")                     ;** Create output time part of string

Posted: Thu Jan 06, 2005 3:01 pm
by ray.wurlod
If you're prepared to write a Routine, you can use the STATUS statement to retrieve lots of information about a file.

You can find sample code here for retrieving some attributes. Read about the STATUS statement in the DataStage BASIC manual.