Page 1 of 1

Deleting a file from DataStage server routine

Posted: Mon Apr 16, 2007 8:23 am
by arnabdey
Can anyone please tell how to delete a file from DataStage server routine. This routine needs to be able to run on UNIX as well as WINDOWS environment.

Posted: Mon Apr 16, 2007 8:28 am
by us1aslam1us
Are we talking about hashed file or flat file as commands will differ from one environment to other. Also why don't you just use Execute command stage or just filter command(if flat file) in sequential file stage?

Hi us1aslam1us

Posted: Mon Apr 16, 2007 8:42 am
by arnabdey
I actually have a server routine with many other things. The requirement is to delete a mere flat file at the end. So I was looking for a Basic command.

[quote="us1aslam1us"]Are we talking about hashed file or flat file as commands will differ from one environment to other. Also why don't you just use Execute command stage or just filter command(if flat file) in sequential file stage?[/quote]

Posted: Mon Apr 16, 2007 8:44 am
by chulett
You're going to need to find the SYSTEM call that tells you the O/S and then build the command appropriately. Difference would be the actual command used and the direction of the slashes. Primarily. :wink:

Posted: Mon Apr 16, 2007 8:46 am
by DSguru2B
For a flat file you can use the following. File is the input argument that will be the fully qualified name of the file to be removed.

Code: Select all

      FUNCTION RemoveFile(File)

      IF system (91)
      THEN
         OS="NT"
         CMD="del ":File
      END
      ELSE
         OS="UNIX"
         CMD="rm ":File
      END

      Call DSExecute(OS, CMD, Output, RtnCd)
      Ans=RtnCd

Hi DSguru

Posted: Mon Apr 16, 2007 9:08 am
by arnabdey
Hi DSguru

But say I use Windows 2000 or 2003 as my server, will the system function return 1.

[quote="DSguru2B"]For a flat file you can use the following. [b]File[/b] is the input argument that will be the fully qualified name of the file to be removed.
[code]
FUNCTION RemoveFile(File)

IF system (91)
THEN
OS="NT"
CMD="del ":File
END
ELSE
OS="UNIX"
CMD="rm ":File
END

Call DSExecute(OS, CMD, Output, RtnCd)
Ans=RtnCd
[/code][/quote]

Posted: Mon Apr 16, 2007 9:10 am
by DSguru2B
It should. Someone here needs to confirm that as I am not sitting on a windoze box.

Posted: Mon Apr 16, 2007 3:31 pm
by ray.wurlod
System(91) is specifically there to answer the Windows/UNIX question.