There are quite a few ways, probably the easiest is to do it in code (either a before/after subroutine or a job control routine). You could also do it using a Folder stage.
To generate the date there are again many options (look in the Routines and Transforms, particularly the SDK). However, ultimately, if all you want is the system date, this is obtainable using:
- the @DATE system variable (which remains constant during job execution)
the DATE() function, which always reports the date "now"
Similarly for the @TIME variable and TIME() function for the time.
Then you need to decide exactly what format you want the date in. For example, let's assume that what you have is the base name, and you want to append the date in YYMMDD and time in HHMMSS format, with underscores between. In the following code fragment, the variable DirPath contains the pathname of the directory where the file is.
Code: Select all
DirPath = "E:\MyDataFiles\"
BaseName = "TheFile"
DateTag = Oconv(Date(), "DYMD[2,2,2]" : @VM : "MCN")
TimeTag = Oconv(Time(), "MTS" : @VM : "MCN")
OldName = DirPath : BaseName
NewName = DirPath : BaseName : "_" : DateTag : "_" : TimeTag
Shell = "NT"
Command = "MOVE " : Quote(OldName) : " " : Quote(NewName)
Call DSExecute(Shell, Command, Output, ExitStatus)
If ExitStatus <> 0
Then
Msg = "Error executing command " : Quote(Command)
Call DSLogWarn(Msg, "Rename File")
End
Minor changes would be required if the server were on a UNIX platform.
An alternative approach would be to use DataStage BASIC's innate ability to treat a directory (folder) as a "table", in which the O/S file names are treated as record keys.
Code: Select all
DirPath = "E:\MyDataFiles\"
BaseName = "TheFile"
DateTag = Oconv(Date(), "DYMD[2,2,2]" : @VM : "MCN")
TimeTag = Oconv(Time(), "MTS" : @VM : "MCN")
OldName = BaseName
NewName = BaseName : "_" : DateTag : "_" : TimeTag
OpenPath DirPath To DirFvar
Then
RecordLockU DirFvar, NewName
ReadU FileContents From DirFvar, OldName
Then
Write FileContents To DirFvar, NewName
Then
Delete DirFvar, OldName
End
Else
Msg = "Error renaming file."
Call DSLogWarn(Msg, "Rename File")
End
Release DirFvar, NewName
Release DirFvar, OldName
End
End
Some error handling and handling of records locked by other process have been omitted for clarity.