. [
[-
[~I
C:
c
If
Purpose:
Performs a command based
on
the
result
of
a condition .
Syntax:
if
[NOT) errorlevel
number
command
or
if
[NOT) string! = = sfring2
command
or
if
[NOT)
exist
filename
command
Comments:
The
if
statement allows conditional
execution
of
commands.
When
the
condition
is
true, MS-DOS
executes
the
command, other-
wise it ignores
the
command.
The
conditions are described as follows:
errorlevel
number
True
if, and only if,
the
previous program
executed
by
command.com
had an
exit
code
of
number
or
higher.
(When
a
program finishes, it
returns
an
exit
code
via MS-DOS.) You
can
use
this condition
to
perform
other
tasks that are based
on
the
previ-
ous
program's
exit
code.
string! = = string2
True
if, and only if, string! and string2 are identical after parame-
ter
substitution. Strings may
not
contain separators,
such
as com-
mas, semicolons, equal signs,
or
spaces.
exist
filename
True
if, and only if,
filename
exists_
If you specify
the
NOT parameter, MS-DOS
executes
the
command
when
the
condition is false.
Example:
The following example prints
the
message "can't find datafile"
if
the
file product.dat
does
not
exist
on
the
disk:
if
not
exist
product.dat
echo
can't
find
datafile
Batch Processing 113
If
Displaying a
conditional message