Maximum PC

Working with Batch Files

-

Batch files are specially created text files that contain a list of Command Prompt commands, which are executed in the order they’re written. They can also be used to call executable programs (use the start command), and are a great way to make repetitive commands easy to process.

You can create and edit batch files in Notepad—place each command with its options on a separate line. When you come to save the file, set “Save as type:” to “All Files (*.*),” before giving the file a .cmd extension.

There’s a number of commands designed for use in batch files. One of the easiest to use is the pause command. Place this in your batch file, and when it’s reached, the Command Prompt throws up a “Press any key to continue” message, and waits for a key to be pressed. You can also make use of the echo command to display text on-screen, and insert an @echo off command at the top of your batch file to prevent the commands themselves from appearing in the Command Prompt window as they’re run.

Other useful commands include call, which enables you to call a second batch file from within the first, plus choice and set for introducin­g interactiv­ity through the form of choices for the end user (you can also introduce conditions through the if and goto commands). Batch files can be run from within the Command Prompt window (you can drag them from File Explorer into the window), or simply by double-clicking them in File Explorer—you’ll see the Command Prompt window appear, and it disappears when the script completes. Visit https:// technet.microsoft.com/library/bb490869.aspx for a handy reference guide.

 ??  ??

Newspapers in English

Newspapers from United States