How to Create
and Use Batch Files

There are at least a couple of ways for writing batch files. One way is to use a plain text word processor such as Notepad, which (for 64-bit operating systems) appears to be the best option for now. Another way (for 16-bit and 32-bit operating systems) is to use the plain text editor, MS DOS Editor. Just type in the file name, Edit, at either the DOS prompt or in the Run command box on the Start menu (for Windows versions XP and earlier). Choose Save from the File menu, type a name for your batch file, and press Enter to save it. Be sure to add the .BAT extension to your file name, too. Next, begin typing the batch file code.

To use Notepad for this purpose, choose it from the All Programs | Accessories folder on the Start menu. You can also type Command Prompt in the Search box on the Start menu for Windows Vista or later and select "Command Prompt" from the Programs group list. Once the command prompt opens, type notepad filename [such as notepad to-do-list.txt] at the command prompt and press Enter to open it. This assumes, of course, that the file you wish to open is in the current directory displayed at the command prompt. To open a file in a different directory, type the complete file path. For instance, typing notepad Desktop\to-do-list.txt at the command prompt will open a file named to-do-list.txt from your Desktop directory. To open a file in a different directory, just specify the directory where your target file resides.

The first step in writing batch file code is to obtain a comprehensive DOS manual (available at most book stores) which contains all of the pertinent DOS commands with a thorough explanation for how to use each one. Next, when you're ready to begin composing your batch file, decide whether you want your code to display on-screen while it executes. Code will display on-screen by default, so if you don't want it to display, you must type as your first line: @Echo off. However, it's always a good idea to make some text visible at the end of the batch job to notify the user that the task has completed. Use that as the last line of your batch file.

On the second line, type the letters CLS, which is code for "clear screen". This is a good idea in case there is other text already displayed on the screen when your batch file begins execution.

On the third line, type the command you want the batch file to perform. For instance, if you want your batch file to format a floppy disk, type the following code: format a: . Note the blank space following the colon and always be sure to include it. Note, also, that this DOS command will invoke the compiled command program,, in the DOS directory (3.x) or in the Windows\Command directory (Win9x and ME) or in the \I386 directory (WinXP Home Edition) or in the Windows\System32 directory (WinXP Pro and later), which will display text on-screen during the format process.

If the drive letter for your floppy disk drive is different than A, insert the appropriate letter. Make absolutely certain the drive letter you specify is the correct one for which you intend to format, or else you could lose valuable data on a disk you didn't intend to format!

There are several parameters you can add to the format command to specify different options you wish to include in the format function. /S, for instance, copies the current DOS's system files onto the floppy disk. /V prompts you to name a volume label for the disk. To specify a label name without being prompted, type /V:labelname, whereas labelname is the name you specify for the volume label. If you use multiple parameters, be sure to include a blank space between each one. For instance, /S /V:labelname.

In order to let your user know when the batch job is complete, it's smart to make a line of text visible with just that message. To do that, though, you'll have to turn @Echo back on and use the command @Echo at the beginning of the line to display your text. See the example below.

Now, to write all this code in its sequence, your batch file should look like this:

@echo off
format a: /S /V:Notes
@echo on
@echo Batch job is complete.

For a comprehensive list of all DOS commands, and with much more detailed instructions on how to write batch files, consult a DOS manual like Running MS DOS Version 6.22 by Van Wolverton, or here's another way.

Choose Help and Support from the Windows XP Start menu and click on the Index icon on the top menu bar. Next, type in "batch files" in the search box and press Enter. When the search completes, click on the "Run a memory-resident program with another program" item under the Suggested Topics | Pick a task section in the Search Results. Now, click on the Related Topics hyperlink at the bottom of that article in the right-hand pane and choose "Batch files" from the pop-up menu. Once that article loads, click the Add to Favorites icon on the menu bar at the top of that pane (not the uppermost menu bar).

Now, you can come back to that article much more quickly the next time you want to read it by clicking on the Favorites icon on the uppermost menu bar of that screen and choose it from the saved list. That's all for now!