Draft for Information Only
ContentMS DOS Command: IF
MS DOS Command: IFReference from Microsoft MS-DOS cmd help DescriptionPerforms 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. SyntaxIF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command
Parameters
ExamplesThe 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 on the hard drive. Therefore, you can test for the null device to determine whether a directory exists on the hard drive. if exist c:\mydir\nul goto process 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 When a program stops, it returns an exit code to MS-DOS. For example, a value of 0 is typically used to indicate that a program was successfully executed. The ERRORLEVEL parameter lets you use exit codes as conditions. 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.
For another example of how the ERRORLEVEL parameter is used, see the CHOICE command. ©sideway ID: 110700199 Last Updated: 7/28/2011 Revision: 0 Latest Updated Links
![]() ![]() ![]() ![]() ![]() |
![]() Home 5 Business Management HBR 3 Information Recreation Hobbies 8 Culture Chinese 1097 English 339 Travel 18 Reference 79 Computer Hardware 254 Software Application 213 Digitization 37 Latex 52 Manim 205 KB 1 Numeric 19 Programming Web 289 Unicode 504 HTML 66 CSS 65 SVG 46 ASP.NET 270 OS 431 DeskTop 7 Python 72 Knowledge Mathematics Formulas 8 Set 1 Logic 1 Algebra 84 Number Theory 206 Trigonometry 31 Geometry 34 Calculus 67 Engineering Tables 8 Mechanical Rigid Bodies Statics 92 Dynamics 37 Fluid 5 Control Acoustics 19 Natural Sciences Matter 1 Electric 27 Biology 1 |
Copyright © 2000-2025 Sideway . All rights reserved Disclaimers last modified on 06 September 2019