Batch Files

Batch Files

Sections: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Index | Next >

IF Example

Learning objective: (3) Demonstrate the use of the IF command in a batch file


Click on image to enlarge.

In this example, note the IF statement in the middle of the batch file. It is to see if the passed parameter is blank or null. If so, the batch file jumps, using the GOTO command, to the error message section.

IF "%1" == "" GOTO err_msg

Test the value being passed by the %1. If %1 is blank, then GOTO the error section of the batch file. If %1 is not blank then processing will continue on to the next line in the batch file.

:err_msg

The ":err_msg" label begins error message section of the batch file.

:end

The ":end" label is the end of the batch file. When a batch file reaches the end of the batch file, it stops and returns control over to the system prompt since there are no more commands to process.

Sections: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Index | Next >