The Ultimate Batch File Book
Description of Chapters

Before you begin to learn to write batch files, these first three chapters will help you understand more global issues relating to batch files.

Chapter 1: Batch Files Are Just Commands For The Operating System. Some of your most useful batch files can be created by simply writing down the commands you use to perform a particular task and then storing that command or those commands in a batch file. This chapter explains that concept in more detail.

Chapter 2: Creating Your Own Batch Files. You have three general ways to write batch files: 1) the COPY command, 2) the editor included with your operating system and 3) some other editor or word processor. This chapter explains the advantages and disadvantages of each of these approaches.

Chapter 3: Batch File Construction. This chapter explains naming conventions and layout considerations you need to understand when you begin to write batch files.

When you finish these three chapters, you will be able to consolidate one or more commands you would normally enter from the command line prompt into a batch file.

Now that you've seen how to name, write, and structure batch files, it's time to look at come of the simpler batch commands. A batch command is a command designed to run inside a batch file. However, most of them will also work from the command line if you have a use for that.

Chapter 4: Documentation or "Why In The World Did I Do That?" The batch language only has a few commands of its own but it can also run any program you own. As a result, some batch files tend to become very long. Using the REM command to document those longer batch files can make following their logic easier when you have to go back and modify them. This chapter explains how to do that.

Chapter 5: Let's Keep It Quiet. The default mode of operation for a batch file is to have command echoing on, which means that commands are displayed on the screen before they are executed by the batch file. By turning command echoing off, your screens will look much neater. This chapter explains how to do that.

Chapter 6: Communicating With The User. Batch files frequently need to "talk" to the user to display information, ask questions or provide warnings. The ECHO command provides the method for doing this. This chapter explains how to use the ECHO command effectively.

Chapter 7: Using High-ordered ASCII Characters. Your batch files can be made much more attractive by using some of the high-ordered ASCII characters. This chapter explains how to use these characters.

Chapter 8: Hold That Batch File! Sometimes you need for the batch file to wait for the user to catch up. Maybe it has put a lot of information on the screen for the user to read or the user needs a chance to press Ctrl-Break and halt the batch file. This chapter explains how to use the PAUSE command in a batch file to suspend its operation until a key is pressed.

Chapter 9: Applications And Problems. Before moving on to the intermediate batch commands, you should understand the commands and concepts covered so far. This chapter is a quick test. Pass it, and you're ready to move on.

Now that you've seen the simple batch file commands, it's time to take a look at some slightly more complex commands. As it turns out, the chapters in this section will be the "meat" of your batch files. As you write your own batch files, you'll find that the vast majority of the batch file commands you use are either the REM or ECHO command or the commands covered in these chapters. Just to be sure, there is a chapter at the end of this section where you can test your knowledge.

Chapter 10: Replaceable Parameters. Unless you have a way to get information into a batch file, it is difficult to have the batch file perform differently each time it runs. Replaceable parameters are a method of adding additional information on the command line that the batch file then has access to. This information can be used as file names, extensions, subdirectories, commands, or just about anything you use in a batch file.

Chapter 11: Using More Than Ten Replaceable Parameters. When it first starts, the batch file only has access to its name and the first nine pieces of information you entered on the command line. This chapter show you how to gain access to additional information.

Chapter 12: Looping And Program Flow. This chapter shows you how to define different execution paths through the batch file and how to create loops within a batch file.

Chapter 13: The Environment. The environment is an important scratch pad for the operating system. It uses the environment to store information that all subsequent programs and batch files have access to.

Chapter 14: Errorlevel. The errorlevel is a one-byte portion of memory that programs can use to communicate to each other or with a batch file. While only a few programs use the errorlevel, many batch file utilities use it to pass results back to the batch file that ran them. This chapter provides an overview of the Errorlevel.

Chapter 15: Punctuation. Many of the batch files you have seen so far have used varying types of command line punctuation to help them perform their work. This chapter documents that punctuation as a resource to help you understand these batch files as well as write more powerful batch files of your own.

Chapter 16: Logic Testing. The different paths you learned to create in Chapter 12 are useless unless you have a method of selecting different paths at different times. Additionally, the loops you learned to create in Chapter 12 are never ending unless you have a way to get out of them. In both cases, logic testing is the solution. This chapter shows you how to build logic testing into your batch files. Logic testing is what turns a batch file away from being just a dumb script the computer plays back into an intelligent program.

Chapter 17: Applications And Problems. Before moving on to the advanced batch commands, you should understand the commands and concepts covered so far. This chapter is a quick test. Pass it, and you're ready to move on.

Now that you've seen the intermediate batch file commands, it is time to take a look at the advanced commands. By the time you finish this section, you will have seen all the native batch commands that are available for you to use in batch files.

Chapter 18: Advanced Logic Testing. In Chapter 13, we covered simple logic testing. This chapter expands logic testing to include all the available logic testing commands batch files offer and some more that are supplied by a utility program.

Chapter 19: Advanced Getting Information From Users. DOS, Windows, Windows 95, and OS/2 make it difficult to get information from the user in a batch file. This chapter discusses some alternative methods for having a batch file query the user.

Chapter 20: Advanced Screen Design 1. Most batch files use a series of ECHO commands to communicate with the user in a very boring fashion. This chapter covers two ways to improve your screens using ASCII files: typing them to the screen, and converting them to a program with a screen compiler.

Chapter 21: Advanced Screen Design 2. This chapter continues where Chapter 20 leaves off by showing you how to used advanced ANSI commands to construct colorful and highly formatted screens. It also briefly covers the many other uses for ANSI.

Chapter 22: Batch File Subroutines. Subroutines are one of the most powerful approaches available to writing complex batch files. This chapter shows you how to use them.

Chapter 23: When Batch Files Don't Work. You are going to occasionally have problems with the batch files you write. While nothing can eliminate the need for you to work through the logic of your batch file to resolve this problem, this chapter shows you some ways to expedite the process.

Chapter 24: Applications And Problems. Before moving, you should understand the commands and concepts covered so far. This chapter is a quick test. Pass it, and you're ready to move on.

We've learned so much about batch files, and now it's time to put that into practice. So far, you've seen a number of batch files that solve very specific problems. For the next few chapters, we will look at how batch files can be a part of the solution for larger problems.

Chapter 25: An Automated Batch File Help System. One problem with having a lot of batch files is remembering which batch file does what. As it turns out, batch files can solve this problem and, in the process, give you a set of very powerful tools for locating the right batch file for your needs.

Chapter 26: Batch File Menus. The most common thing you do with your computer is run different programs. Under Windows, Windows 95, and OS/2, the operating system takes care of presenting you with a list of program options to select from. Under DOS, you can use a menu to do the same thing-with a lot less overhead. This chapter will show you how to use batch file menus.

Chapter 27: A Document Archival System. Never lose an important file again! That is a strong claim, but this chapter will show you how.

Chapter 28: Simulating DOSKEY Using Batch Files. Doskey was introduced in version 5 of MS DOS. It gives users command line recall, keyboard macros, and the ability to enter multiple commands on a single command line. As it turns out, all these features can be added to other versions of DOS and to OS/2 using nothing more than batch files and this chapter shows how. It even turns out that there are significant advantages to using batch files over Doskey.

Chapter 29: Smaller Batch File Applications. This chapter presents a number of batch file applications that were too small to put in a separate chapter.

Chapter 30: Applications And Problems. Think of this as a final exam. You get to try out everything you have learned in this book so far.

By now, you can call yourself a batch file master. Anyone making it this far in this book has a clear idea of what batch files can do and can write some very powerful batch files. These chapters are not necessary to writing useful batch files but they are necessary if you want to write the most powerful batch files possible.

Chapter 31: Writing Your Own Batch File Utilities (DOS and Windows). Writing your own batch file utilities is not as hard as you think. In fact, it is often one of the easier programming tasks you can tackle. This chapter shows you how to write several simple batch file utilities in QBasic, Builder Lite and Pascal. Even if you do not "speak" either of these three languages, the insights this chapter offers for programming batch file utilities can make that task easier in any language.

Chapter 32: Writing Your Own Batch File Utilities (OS/2). The REXX language that comes with OS/2 is as powerful as Basic and easily interacts with batch files. It has access to the master copy of the environment and can easily set errorlevels. All this makes it the perfect language for writing OS/2 batch file utilities. This chapter first provides a brief tutorial on REXX and then describes several REXX batch file utilities along with common modifications you might want to make to these programs.

Chapter 33: Modifying DOS With DOSKEY And Batch Files. There is a lot of interest in changing the names of DOS commands or even changing the way they work. Of course, with external commands you just rename the program file to change the name of the command, e.g. rename FORMAT.COM to PREPARE.COM and instantly the command to format a disk on your system is "Prepare" but that does not work for internal commands and does not change the way the commands work. By combining DOSKEY with batch files, you can actually change the way commands work. This chapter will show you how.

Chapter 34: Getting Input From The User. These utility programs let you prompt the user for information while the batch file is running rather than depending on replaceable parameters. Some utilities accept a single character from the user and store it in errorlevel while others accept multiple keystrokes from the user and store them in the environment. Some of the utilities allow you restrict the types of keystrokes you will accept from the user.

Chapter 35: Communicating With The User. Chapters 20 and 21 discussed the alternatives you have with a batch file and Ansi for communicating with the user. The utilities discussed in this chapter enhance the ability of a batch file to communicate with the user.

Chapter 36: Menu Programs. Automated menu programs are very numerous. The last time I counted, I found over 100 different programs! A few menu programs that work well with batch files are discussed in this chapter.

Chapter 37: Dealing With Files, Disks, and Subdirectories. Batch files have very limited abilities to work with files, disks and subdirectories. These utilities enhance these abilities.

Chapter 38: Batch File Utilities Sets. These utilities collect many functions into one package. Often, just one of these sets will give you all the utility you need.

Chapter 39: Other Batch File Utilities. These are utility programs that did not fit into any of the above categories.

Chapter 40: Alternative Batch File (DOS). These programs completely replace the batch language with a language of their own.

Chapter 41: Windows Batch File Utilities. These utilities are designed to enhance DOS batch files that are running under Windows.

Chapter 42: Windows Alternative Batch File Languages. These programs completely replace DOS batch files running under Windows with a batch language written especially for Windows.

Chapter 43: OS/2 Batch File Utilities. The main alternative batch language for OS/2 is REXX. It has all the programming power of Basic or Pascal yet it can issue a command to the operating system as easily as a batch file. REXX and numerous batch file utilities written in REXX were covered back in Chapter 32. The remaining OS/2 batch utilities are covered in this chapter.

The appendices in this section are designed to give you quick access to a large amount of information. Often, this information is presented in the very briefest of fashions. For more information, refer back to earlier sections of this book or to your DOS manual.

Appendix A: Solutions To Problems. This appendix presents a solution to each of the problems in the book. These are not the only solutions, and your solution might even be better than the one given!

Appendix B: Batch File Documentation. This appendix provides brief documentation on the batch files that are included on the disk that comes with this book.

Appendix C: Files On CD-ROM. This appendix lists the subdirectories on the CD-ROM and describes the files in each subdirectory.

Appendix D: Editors And Word Processors. This chapter briefly describes the editors that come with the different operating systems. It also describes how to use the editor that comes with this book, which has on-line batch file help, as well as using your word processor to write batch files.

Appendix E: Icons. This chapter describes the icons and icon tools included on the CD-ROM.

 

 

© 2002 by Ronny Richardson, All Rights Reserved