|
Performs conditional processing in batch programs. If the condition
specified in an if command is true, Windows 2000 carries out the
command that follows the condition. If the condition is false,
Windows 2000 ignores the command in the if clause, and executes
any command in the else clause, if one has been specified. if [not] errorlevel number command
[else expression] if [not] string1==string2
command [else expression] if [not] exist filename command
[else expression] With command extensions enabled: if [/i] string1 compare-op string2
command [else expression] if cmdextversion number command
[else expression] if defined variable command
[else expression] Parameters not Specifies that Windows 2000 should carry out the command only if the
condition is false. errorlevel number Specifies a true condition only if the previous program run by Cmd.exe returned
an exit code equal to or greater than number. command Specifies the command that Windows 2000 should carry out if the
preceding condition is met. string1==string2 Specifies a true condition only if string1 and string2 are
the same. These values can be literal strings or batch variables (%1,
for example). Literal strings do not need quotation marks. exist filename Specifies a true condition if filename exists. compare-op one of the following three-letter comparison operators:
/i The /i switch, when specified, forces string comparisons to ignore case.
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. cmdextversion number The cmdextversion conditional works just like errorlevel,
except it is comparing against an internal version number associated with the
Command Extensions feature of Cmd.exe. The first version is 1. It will be
incremented by one when significant enhancements are added to the command
extensions. The cmdextversion conditional is never true when command
cxtensions are disabled. defined variable The defined conditional works just like exist except it
takes an environment variable name and returns true if the environment
variable is defined. Three variables are added with this conditional: %errorlevel%,
%cmdcmdline%, and %cmdextversion%. %errorlevel% expands 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:
You can also use the comparison operators listed above at compare-op:
%cmdcmdline% expands 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. %cmdextversion% expands into the 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. expression In an else clause, an expression consists of a
Windows 2000 command and any parameters to be passed to the command. |