O'Reilly logo

Windows XP in a Nutshell by Troy Mott, Tim O'Reilly, David A. Karp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

if

Synopsis

Execute a command if certain conditions are met.

Syntax

if [not] string1==string2 
                     command [arguments]
if [/i] string1 compare-op string2 
                     command [arguments]
if [/i] string1 compare-op string2 
                     command [arguments]
if [not] exist filename 
                     command [arguments]
if [/i] string1 compare-op string2 
                     command [arguments]
if [not] exist filename 
                     command [arguments]
if [not] errorlevel n 
                     command [arguments]

Description

Conditional branching lets your batch file test to see whether a condition is true, and if it is, instructs the batch file to execute a command or continue execution at another location in the batch file (via the goto command). The following options can be used with the if command:

command [ arguments ]

The command to execute or the program filename to run. This can be anything you’d normally type at a command prompt; arguments are the options, if any, to pass to the command.

not

Specifies that command should be carried out only if the condition is false; not valid with compare-op.

string1==string2

Specifies a true condition if the specified text strings match. String1 and string2 must be enclosed in quotation marks or parenthesis.

string1 compare-op string2

Performs a more flexible comparison than string1 == string2, shown above. The compare-op term can be one of the following:

EQU

Equal

NEQ

Not equal

LSS

Less than

LEQ

Less than or equal

GTR

Greater than

GEQ

Greater than or equal

/i

Specifies a case-insensitive comparison; used only with compare-op.

exist filename ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required