Page 1 of 1

need to include sysdate into the file name

Posted: Tue Jul 08, 2008 9:13 am
by Jagan617


Actually i am ftping the file from the upstreams to ETL server, in the ETL server i need to keep the filename as TCyyyymmdd.txt where YYYYMMDD is the current date.

Can anyone assist me in this.

Re: need to include sysdate into the file name

Posted: Tue Jul 08, 2008 10:19 am
by mail2hfz
Jagan617 wrote:

Actually i am ftping the file from the upstreams to ETL server, in the ETL server i need to keep the filename as TCyyyymmdd.txt where YYYYMMDD is the current date.

Can anyone assist me in this.

After FTP,you can rename as

mv filename filename_`date '%Y%m%d`

Posted: Tue Jul 08, 2008 3:11 pm
by ray.wurlod
That is trickier to do on a Windows operating system. You could use a routine from a Routine activity. The following code is generic - it will work on either UNIX or Windows. Error handling has been omitted for clarity.

Code: Select all

FUNCTION AddDateToFileName(FileName)
* Add yyyymmdd between base name and suffix.
* FileName is the pathname of the file to be changed.
* Generates and executes appropriate rename command.

   Ans = @NULL
 
   Elements = DCount(FileName, ".")
   BaseName = Field(FileName, ".", 1, Elements - 1)
   Suffix = Field(FileName, ".", Elements, 1)

   Call !GET.PATHNAME(FileName, DirPath, EntryName, StatusCode)

   NewFileName = EntryName : Oconv(@DATE,"DYMD[4,2,2]":@VM:"MCN") : "." : Suffix

   If System(91)
   Then
      Shell = "DOS"
      Command = "REN " : FileName : " " : NewFileName
   End
   Else
      Shell = "UNIX"
      Command = "mv " : FileName : " " : NewFileName
   End

   Call DSExecute(Shell, Command, Output, ExitStatus)
   Ans = ExitStatus


RETURN(Ans)