processing in batch programs.
IF [NOT] ERRORLEVEL
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command
Specifies that Windows XP should carry out the command
only if the condition is false.
Specifies a true condition if the last program run returned
an exit code equal to or greater than the number
Specifies a true condition if the specified text strings
Specifies a true condition if the specified filename exists.
Specifies the command to carry out if the condition is
met. Command can be followed by ELSE command which
will execute the command after the ELSE keyword if the
specified condition is FALSE
The ELSE clause must
occur on the same line as the command after the IF. For
IF EXIST filename. (
) ELSE (
echo filename. missing.
The following would
NOT work because the del command needs to be terminated by a
filename. del filename. ELSE echo filename. missing
Nor would the
following work, since the ELSE command must be on the same
line as the end of the IF command:
filename. del filename.
ELSE echo filename. missing
The following would
work if you want it all on one line:
filename. (del filename.) ELSE echo filename. missing
Extensions are enabled IF changes as follows:
IF [/I] string1
compare-op string2 command
IF CMDEXTVERSION number command
IF DEFINED variable command
where compare-op may
be one of:
EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal
and the /I switch,
if specified, says to do case insensitive string compares.
The /I switch can also be used on the string1==string2 form
of IF. These comparisons are generic, in that if both
string1 and string2 are both comprised of all numeric
digits, then the strings are converted to numbers and a
numeric comparison is performed.
conditional works just like ERRORLEVEL, except it is
comparing against an internal version number associated with
the Command Extensions. The first version is 1. It will be
incremented by one when significant enhancements are added
to the Command Extensions.
conditional is never true when Command Extensions are
conditional works just like EXISTS except it takes an
environment variable name and returns true if the
environment variable is defined.
expand into a string representation of the current value of
ERRORLEVEL, provided that there is not already an
environment variable with the name ERRORLEVEL, in which case
you will get its value instead. After running a program,
the following illustrates ERRORLEVEL use:
echo Program had return code 0
echo Program had return code 1
You can also using
the numerical comparisons above:
IF %ERRORLEVEL% LEQ 1 goto okay
expand into the original command line passed to CMD.EXE
prior to any processing by CMD.EXE, provided that there is
not already an environment variable with the name CMDCMDLINE,
in which case you will get its value instead.
will expand into a string representation of the current
value of CMDEXTVERSION, provided that there is not already
an environment variable with the name CMDEXTVERSION, in
which case you will get its value instead.