Home   MS-DOS Home   A-Z   NS Utilities   Command Syntax

IF

Home >> MS-DOS Reference >> Command Categories >> Batch File Commands >> IF

Batch File Commands

Batch File Commands


Summary
Description
Command Syntax
Comments
Supported DOS versions: All versions
How easy to use? Easy
How safe to use? Very safe
How common? Very common
Internal or external command? Internal

Description

Allows conditional commands in batch files.

Command Syntax

IF something_is_true do_something

or

IF NOT something_is_true do_something

Using NOT in this way allows you to check the reverse of something. If, for example, you wanted to check if a file did not exist you could do it like this:

IF NOT EXIST filename do_something

Comments

Unfortunately, IF does not provide an ELSE command. To get around this, I suggest the following:

IF something GOTO Next
REM The "ELSE" statements could be inserted here
GOTO End
:Next
REM Do whatever should happen if something is true.
:End

Home Home
MS-DOS MS-DOS Home
A - Z Index A - Z Index

Top of page
Summary
Description
Command Syntax
Comments




Top of page    Home    MS-DOS Home    NS Utilities
Copyright © 2005 Marcus Houlden  |  Copyright and Data Protection

Printed from the NukeSoft MS-DOS Reference. Copyright © 1995 - 2006 Marcus Houlden