I have the following bit of code at the start of a program that creates a number of files in &MYPATH. The idea being that I want to delete all the files in that folder before I create all the new ones later in the program.
What I'm not sure is if the WINNT del command will complete before the rest of the program runs? If not, is there a way to make sure it does please?
-SET &MYPATH = 'E:\mypath\'; -SET &DELETEFILE = &MYPATH | '*.*'; -RUN -TYPE &DELETEFILE -WINNT del /q /f &DELETEFILE -RUN The rest of my program here....
If there is a chance it won't have finished, I could end up with a mess of files in the folder.
DuncanThis message has been edited. Last edited by: FP Mod Chuck,
Check out the SYSTEM function. This will populate a variable with the return code of the OS command so that you can test for success/failure before continuing.
Link to online help
Thanks for the super quick reply. I had a look at the System command but I'm either doing something wrong or it doesn't work on our setup.
These were my two attempts:
-SET &RETURNCODE = SYSTEM(29, 'WINNT del /q /f E:\mypath\*.*', 'D4'); -TYPE returncode was &RETURNCODE -SET &RETURNCODE = SYSTEM(31, 'COMMAND del /q /f E:\mypath\*.*', 'D4'); -TYPE returncode was &RETURNCODE
These are the results:
'WINNT' is not recognized as an internal or external command, operable program or batch file. returncode was -1 'COMMAND' is not recognized as an internal or external command, operable program or batch file. returncode was -1
It's nearly 8pm here so signing off until the morning now.
-SET &RETURNCODE = SYSTEM(29, 'del /q /f E:\mypath\*.*', 'D4'); -TYPE returncode was &RETURNCODE
Win10 / IE11
AHTML EXL2K PDF
Thanks dbeagan, that fixed it
Handling the result?
If I understand the documentation correctly, I should just need to check that I got a value of 0 in &RETURNCODE as processing is suspended until the operation is complete?
Confirm understand of possible return values
Interestingly, even when the file was not found, the value of &RETURNCODE was still 0. Guessing for the SYSTEM command, I get '0' if I have submitted a valid command, regardless of whether if finds any files to delete and '-1' if there if it's an invalid command?
You will get a return code of 0 if the command is valid and the command ran successfully.
If you run your command (on the server remember!) using CMD.EXE then you will get the same response.
If you want to get differing return codes from your call then look at writing a python or powershell procedure to call that will give you more meaningful return codes.
I think provided I get the 0 once the command has completed, I'm happy to let my program continue. If I get some time, I will explore the powershell option.
|Powered by Social Strata|