" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#008000" VLINK="004000" ALINK="#00C000">
IF Command
If the order of batch file processing depends on external conditions
then command IF (CONDITIONAL transfer) is used.
Syntax: IF <condition> <command>,
where condition is one of circumstances described below;
command is any DOS command to be executed if the condition is true.
Otherwise execution of the batch file resumes starting from
the line immediately following that containing IF command.
Using semantic notation we can make the following sequence:
condition::=[NOT] {string<rel>string|
ASK [YES:NO] <message> |
ERRORLEVEL[<rel>]<number> |
EXIST[{ALL:ANY}]<FILELIST>}
In other words, the condition is a string like one of the strings
above. It can be preceded by NOT instruction which inverts its meaning.
The conditional operator used in batch files permits to use only one
condition at a time. A number of conditions in logical operations can be
brought together only by way of using several IF operators in a row. For
example, operation AND between condition1 and condition2 can be made
possible through writing a conditional operator as a command part of
another. In other words, the string IF <condition1> IF <condition2>
<command>
will execute AND operation.
Evidently, OR operation can be made possible by two consecutive IF
operations located in different strings. The following strings do the OR
operation between condition1 and condition2:
IF <condition1> goto cond_met
IF <condition2> goto cond_met
...... - strings to be processed if the conditions are not true.
:cond_met
...... - strings to be processed if at least one of the conditions is
true.
See for each of the condition types in detail:
1. string1<rel>string2
2. ASK [{Y[es]|N[o]}] <message>
3. ERRORLEVEL [<rel>] <number>
4. EXIST [{ALL|ANY}] <FILELIST>