I have a Winbatch script that uses the FileDelete command but sometimes the file I am trying to delete is in use by another program/user so my FileDelete fails and terminates my program
How can I prevent this from happening or recover from the filedelete failure and continue processing.
Thanks
Garth
Take a look at FileExist().
Jim
Generally, FileDelete errors because the file is marked read-only or the file is currently opened without read sharing by another process. If the problem is the later, you can check for the no read sharing status by calling the FileExist function. It will return 2 when the file does not have read sharing enabled.
The alternative would be to use WinBatch error handle techniques. You can either use the ErrorMode function around the call to FileDelete or use IntControl 73 for a more comprehensive error handler. Check out the WIL Consolidated Help file for details.
Of course if the file is simply marked by the old DOS attributes as read-only, you can detect and change them using the FileAttr* functions.
Thank you all for your assistance - I used the intcontrol option to recover from the failure after writing a warning to the Syslog.
Garth