if(CMD) 19 June 1992 if(CMD) Name if - perform conditional processing in batch programs Syntax if [not] errorlevel number command if [not] string1==string2 command if [not] exist filename command Description If the condition specified in 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. 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. Note When a program stops, it returns an exit code to MS-DOS. The errorlevel parameter lets you use exit codes as conditions. For examples of using the errorlevel parameter to process exit codes, see the following ``Exam- ples'' section and the backup command. Examples The following example displays the message ``Can't find data file'' if MS-DOS cannot find the file PRODUCT.DAT: if not exist product.dat echo Can't find data file The following example displays an error message if an error occurs during formatting of the disk in drive A. If no error occurs, the error message is skipped. :begin echo off format a: /s if not errorlevel 1 goto end echo An error occurred during formatting. :end echo End of batch program. The following example tests for the existence of a directory. The if command cannot be used to test directly for a directory, but the null (NUL) device does exist in every directory. Therefore, you can test for the null device to determine whether a directory exists. if exist c:\mydir\nul goto process