Batch files revisited
Q How do I create a batch file in MS-DOS and Windows 95? Thanks. - Kien A A batch file is a plain vanilla text file that contains DOS commands. However, as far as DOS is concerned, a batch file is also an executable file, that is, a program. When a batch file is executed, the operating system usually reads and performs each DOS command in the file sequentially, until the end of the file is reached. Batch files can be short and simple or long and sophisticated, depending on what they are designed to do. They are particularly useful for creating menus and rapidly performing frequently used, long sequences of DOS commands. For example, you could create a batch file first to perform a number of DOS commands, then launch Windows and open a new file in your word processor. Or you could create a batch file to backup all of the word processing files in a directory to a Zip file on a floppy disk and then delete the original files on your hard disk. The possibilities are endless and are really only limited by your imagination and, of course, by the available DOS commands. The best known batch file is the autoexec.bat file, which can be found on almost every PC. It contains all the instructions and settings that are needed every time you boot your PC and it runs automatically on start-up. Most other batch files are executed by typing the name of the file at the DOS prompt. You can create and edit batch files with any text editor or word processor that can save a file in text-only format, such as the Edit program in DOS or Notepad in Windows. It's best to avoid word processors such as Word or WordPerfect, because their default file formats may corrupt your batch file by adding invisible formatting codes such as page breaks and paragraph markers. Caption:Batch files can be created in any text editor HereÆs how to create a simple batch file called hello.bat in DOS: 1. At the DOS prompt, type edit hello.bat. Make sure that the file extension is .bat. 2. Type in the following DOS commands that will run when hello.bat is executed: @echo off echo "Hello world!" 3. Save the file by pressing <Alt>-<F>-<X>, then <Enter>. To create the same batch file in Windows 95, select Start-Programs-Accessories-Notepad. Then type in the DOS commands: @echo off echo "Hello world!" Next, select File-Save As, type hello.bat in the File Name box, select Text Documents in the Save as type box and press the OK button. Finally, select File-Exit to close Notepad. To run your batch file, enter hello at the DOS prompt, or double-click the hello.bat file in Windows 95. As you watch, DOS will sequentially run each command contained in your batch file. - Belinda Taylor |
Category:newbie Issue: June 1999 |
These Web pages are produced by Australian PC World © 1999 IDG Communications