Delete File If Found
I Have a Batch Script with a Line Like This: Del "%Target_Dir%\Packages. Config" but If Packages. Config Does Not Exist in the Target Directory It Produces an...
I have a batch script with a line like this:
del "%TARGET_DIR%\packages.config"
But if packages.config does not exist in the target directory it produces an error.
Could Not Find
\\...\packages.config
Is there a command line switch del that will prevent raising an error the target file is not found? I'm open to using an if exists if I have to, but I have a number of similar commands, and I'd like to avoid having to do that for every single file I might want to delete.
2 Answers
You could functionalize your IF EXISTS/DEL calls so that the code isn't repeated a ton; for doing faux functions in DOS, see this.
They use GOTO statements to implement functions, but it should work the same.
From that page:
Example Function:
:myDosFunc - here starts my function identified by it`s label
echo. here the myDosFunc function is executing a group of commands
echo. it could do a lot of things
GOTO:EOF
Calling the function:
call:myDosFunc
For usage on IF EXISTS, see this.