I need to run a utility only if a certain file exists. How do I do this in Windows batch?
This question is related to
windows
batch-file
Try something like the following example, quoted from the output of IF /?
on Windows XP:
IF EXIST filename. ( del filename. ) ELSE ( echo filename. missing. )
You can also check for a missing file with IF NOT EXIST
.
The IF
command is quite powerful. The output of IF /?
will reward careful reading. For that matter, try the /?
option on many of the other built-in commands for lots of hidden gems.
C:\>help if
Performs conditional processing in batch programs.
IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command
Source: Stackoverflow.com