IF

RECENT NEWS

12/18/2015 - Hello! We're excited to announce that Mental Works Computing Software will soon be featuring

12/11/2015 - We're going to announce Dr.Batcher 3.0 Alpha with batch files debugger support soon. If you want to start...

News history...

TESTIMONIALS

Rob van der Woude:
"Mental Works Computing Software has created a nice tool for...

Andrew Jaritsyn:
“I used to write batch files with the help of Notepad, but...

Steve H.:
“This tool helped me to write some batch files in a couple...

More...

IF

Performs a command conditially.

Syntax:

IF [not] Condition Command1 [Else Command2]

Not – makes the condition negative

Condition – specifies the condition for the Command1 to run. There are several available types of conditions:

Else – makes the command interpreter understand that Command2 should be executed if Condition is false.

Command2 – command to be executed if Condition is false.

Usage:

You must use ELSE clause on the same line with IF command. The only way to escape this is using brackets surrounding commands.

All comparisons are string, so not only numbers can be compared.

Examples:

Existence of a file:

IF EXISTS c:\some.file ECHO File exists

Comparison:

IF %var1 LSS %var2 ECHO %var1 is less than %var2 ELSE ECHO %var1 is greater than %var2

 

Subscribe batch files programming newsletter (no spam):

Subscribe

Unsubscribe