5.8. Batch File Basics

The first part of this chapter shows you several basic commands that make the command prompt easier to use — as well as a powerful ally. In the following sections, you find out how to write a batch file, which makes the command prompt an even more powerful tool. A batch file is simply a string of commands, which could have been typed at a command prompt, chained together to automate a process.

5.8.1. Starting your file

To start, you need a place to put the commands that you want to execute. To do this, open the text editor of your choice, make a new text file, and save it with a .bat extension.

If you're using a Windows-based editor (such as Notepad) and the operating system option of Hide File Extensions for Known File Types is enabled, you must enclose your filename in quotation marks when saving it.

If you want file extensions to show, use the following steps:

  1. Open My Computer or Computer for Vista users.

  2. Choose ToolsFolder Options.

  3. Click the View tab.

  4. Clear (to show) the Hide File Extensions for Known File Types check box.

  5. Click OK.

With your batch file open in the text editor, you can now type any commands you want, but remember to put only one command per line in your file. You can use this file to create, copy, or delete files, or anything else that you ...

Get CompTIA A+® Certification All-In-One For Dummies®, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.