5.1.4. Examples of IF commandΒΆ
Note
For advanced help, see IF.
Sample script which shows behaviour of IF EXIST when a file exists.
When we run command as shown below:
1IF EXIST basic-dos-loop-1234.bat echo basic-dos-loop-1234.bat Exists
The output is:
basic-dos-loop-1234.bat Exists
Sample script which shows behaviour IF EXIST for a missing file.
When we run command as shown below:
1IF NOT EXIST missing_file echo missing_file does not exist
The output is:
missing_file does not exist
Sample script which shows usage of ELSE
for IF command.
When we run command as shown below:
1IF EXIST missing_file2 (
2 echo Really? missing_file2 exists?
3) ELSE (
4 echo missing_file2 does not exist
5)
The output is:
missing_file2 does not exist