- Why Batch Files?
- Creating and Using Batch Files
- Batch File Programming
- Displaying Information in Batch Files
- Argument Substitution
- Argument Editing
- Conditional Processing with If
- Processing Multiple Arguments
- Working with Environment Variables
- Processing Multiple Items with the For Command
- Using Batch File Subroutines
- Prompting for Input
- Useful Batch File Techniques
Batch File Programming
In the following sections, I'll discuss programming techniques that take advantage of the extended commands provided by the CMD shell. The commands that are most useful in batch files are listed in Table 12.1.
Table 12.1. Batch File Commands
Command |
Use |
call |
Calls batch file subroutine |
echo |
Displays text to the user |
setlocal/endlocal |
Saves/restores environment variables |
exit |
Terminates batch file |
for |
Iterates over files or folders |
goto |
Used for flow control |
if |
Executes commands conditionally |
pause |
Lets the user read a message |
pushd/popd |
Saves/restores the current directory |
rem |
Used for comments and documentation |
set |
Sets environment variables, performs calculations, and prompts for user input |
shift |
Scans through command-line arguments |
start |
Launches a program in a different window |
The syntax and options for these commands were described in Chapter 11. If you've written batch files for DOS, Windows 9x, and Windows NT, you'll find that most of these commands have been significantly enhanced, so even if you are familiar with these commands, you should read their descriptions in Chapter 11.