Command IF
Function:
Perform conditional processing in a batch file.
Syntax:
IF [/I][NOT] condition command
or
IF [/I][NOT] condition ( command(s) ) ELSE command
or
IF [/I][NOT] condition { command(s) } ELSE command
/I Perform a case insensitive compare. condition Is one of the following :-
( expr ) Evaluate the parameter expr. A zero result is false, otherwise the condition is true. Parameter expr follows the same rules as parameter expr for command CALC. The brackets around parameter expr are mandatory and must be specified. CMDEXTVERSION number Specifies a true condition if the extension version is greater then or equal to number. DEFINED variable Specifies a true condition if the environment variable exists. ERRORLEVEL number Specifies a true condition if the last program returned an exit code greater than or equal to number. EXIST filename Specifies a true condition if the filename exists. EXISTCLASS "text" Specifies a true condition if the window class "text" exists. EXISTWINDOW "text" Specifies a true condition if the window caption "text" exists. string1==string2 Specifies a true condition if string1 and string2 are the same. string1 comp-op string2 comp-op can be one of the following :-
EQU equal NEQ not equal LSS less than LEQ less than or equal GTR greater than GEQ greater than or equal Specifies a true condition when comp-op is satisfied. When string1 and string2 are both integer numbers then both string1 and string2 are converted to integers and a numerical compare is performed.
command Specifies the command to carry out if the condition is met. Parameter command can also be another IF command. NOT Carry out the command only if the condition is false.
Note:
The parameters string1 and string2 do not need to be enclosed in quote characters.
When using the IF ELSE syntax, the brackets or braces around parameter command(s) are mandatory and must be specified. See Command Grouping for more information.
Examples on using IF.
Also see command CALC and Batch Files.
