The if
Command
if
performs conditional actions if the specified conditions are found. It can be combined with any script command, including itself, allowing for nested if
commands.
See some example constructions below:
Syntax | Example |
---|---|
if [not] errorlevel number scriptCommand
Where
|
if errorlevel 0 echo "errorlevel is greater/equal to 0" |
if [not] string1==string2 command
Where either string can be a string constant or an environment variable. Strings can be any string of Unicode characters. |
if abc==%xyz% echo "value of environment variable xyz is equal to abc"
If a variable contains white space, enclose the string in quotation marks ("")
|
if [not] exist filename command
Where filename can include the directory path as well as the file name. If a file or folder is found (or not found when not is present), the command is executed. If you specify directory information in filename, the command will search the specified directory. Otherwise, it will search the current directory. Use 1:\ to specify device root folder. |
if exist "1:\IPSM\abc.cab" echo "1:\IPSM\abc.cab exists" |
if [not] procexists processName command
Where if processName is found running in the memory of the device, the specified command is executed |
if procexists filesys.exe echo yes |