help.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
IF
Examples
────────────────────────────────────────────────────────────────────────────
 
                                     IF
 
Performs conditional processing in batch programs. If the condition
specified by an IF command is true, MS-DOS carries out the command that
follows the condition. If the condition is false, MS-DOS ignores the
command. You can use this command only in batch programs.
 
Syntax
 
    IF [NOT] ERRORLEVEL number command
 
    IF [NOT] string1==string2 command
 
    IF [NOT] EXIST filename command
 
Parameters
 
NOT
    Specifies that MS-DOS should carry out the command only if the condition
    is false.
 
ERRORLEVEL number
    Specifies a true condition only if the previous program run by
    COMMAND.COM returned an exit code equal to or greater than number.
 
command
    Specifies the command that MS-DOS 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.
 
                                      ♦