Commands Used in Batch Programs

Batch programs (also called batch files) allow you to simplify routine or repetitive tasks. A batch program is an unformatted text file that contains one or more commands and has a .BAT or .CMD filename extension. When the filename is typed at the command prompt, the commands in the file are run sequentially.

Any command can be included in a batch file. In addition, several commands allow conditional processing of the commands in the batch file. For example, the if command carries out a command based on the results of a condition. Other commands allow you to control input and output and to call other batch programs. You can use the following commands in batch programs.

Commands for Use in Batch Files

Command

Purpose

call

Calls one batch program from another without causing the first batch program to stop.

choice

Prompts the user to make a choice in a batch program. Displays a specified prompt and pauses for the user to choose from among a specified set of keys.

echo

Displays or hides the text in batch programs when the program is running. Also indicates whether command-echoing is on or off.

for

Runs a specified command for each file in a set of files. You can use this command in batch programs or at the command prompt.

goto

Directs the operating system to a line in a batch program that is marked by a label you specify. You can use this command only in batch programs.

if

Performs conditional processing in batch programs. You can use this command only in batch programs.

pause

Suspends processing of a batch program and displays a message that prompts you to press any key to continue. You can use this command only in batch programs.

rem

Enables you to include comments (remarks) or prevent commands in a batch program or CONFIG.SYS from running.

shift

Changes the position of replaceable parameters in a batch program. You can use this command only in batch programs.