DESKMATE 3 BATCH FILE TIPS This text file contains of excerpts from the book GETTING THE MOST OUT OF DESKMATE 3, by Michael A. Banks, published by Brady Books/Simon & Schuster, and available in your local Tandy/Radio Shack or Waldenbooks store now. The tips in this file (excerpted from Chapter 15 of the book) are typical of those found throughout the book. The tips and the book are for DeskMate 3.2, 3.3 and later versions and come from both the first and second editions of the book. This text is Copyright, 1989, 1990, Michael A. Banks. Permission is hereby granted to copy and upload the text in this file to computer bulletin boards and other online services ONLY if the entire contents are retained in complete and unmodified form, including this statement and copyright notice. (Please write P.O. Box 312, Milford, OH 45150, regarding user group newsletters.) *GETTING DEEPER INTO DOS WITH BATCH FILES* DeskMate's File and Directory menus--particularly those on the desktop--offer several important file-related commands and options. You can copy, delete, and rename files via the File menu, and create, change, and delete directories via the Directory menu. The desktop Disk menu will even report on the space available on a disk, format a disk, and perform a complete diskcopy operation (erasing files on the destination disk before it copies files from the source disk). As convenient as these commands are, they do not provide everything you need. You cannot, for instance, access DOS's DIR command directly, which is unfortunate, because to view a list of files in a disk or directory other than the current one takes some time. You must change directories, which takes a couple of seconds, then switch to the Tree view, which again takes time, and is inconvenient if you prefer to work from the Menu view. It would be much better if you could type DIR or DIR followed by the name of a drive and/or directory. Fortunately, there is a way to do just that, using batch files. As explained in Chapter 5, a batch file is a kind of program that you can use to issue DOS commands, such as DIR, DEL, etc., and commands used to run programs. You can run batch files using the Run... option on the Files menu. Thus, you can create a batch file that issues a DIR or DEL command, run it using the Run... option, and achieve the same effect as you would typing the commands from DOS. (When you use Run... , DeskMate sends what you enter in the "Program:" and "Data File:" edit boxes directly to DOS, as if you had typed a program name and data file in that order. This makes for some interesting possibilities, as you will learn.) As mentioned, you can also run non-DeskMate programs via batch files--with or without data file specifications. Some examples follow. *Creating Batch Files for Use While Running DeskMate* The process of creating a batch file to run from within DeskMate is no different from creating any other batch file. (You should not, however, end a batch file with a blank line, as explained later.) There are some special considerations involving such a batch file's contents. These are detailed in this and ensuing sections of this topic. Let's try creating a batch file. Say you frequently need to view the contents of a directory called TEXT in which you keep files created by Text. You can create a batch file in your DeskMate directory that will display the full contents of TEXT directory. To create the file, make sure you are in the DeskMate directory, then type COPY CON DIRTEXT.BAT, then enter this line: DIR \TEXT After entering this line, press F6 and press ENTER; this will write the file to disk. If you have a lot of files in the TEXT directory, you may want to add /W to the end of the line; this displays the filenames five across, rather than one across. (When a directory is displayed with the /W option, the file sizes and time/date stamps aren't displayed, however). When you want to use the batch file, select Run... from the File menu, and enter DIRTEXT in the Program: edit box. Let's try another, this one to run, for the sake of example, the "Speed Disk" program in the Norton Utilities. At the DOS prompt, type COPY CON S.BAT and enter the following line: SD A: (Remember to press F6 and ENTER to save the file.) This batch file issues the command to start Speed Disk (SD), along with a drive specification. If you have the Norton Utilities, running this batch file will begin the process of optimizing a disk in your computer's drive A. *Enhancing DeskMate Batch Files* As I implied a few lines back, there are some special considerations involved when it comes to how a batch file runs from DeskMate. Which is to say there are problems and ways to overcome them. And there are some nice enhancements you can add to batch files that make them do more than just issue DOS commands. We'll take a look at some problems, solutions, and enhancements here. *Pausing the Display*. If you started DeskMate and ran the DIRTEXT.BAT file described a few lines back, you noticed that it has one drawback: DeskMate's desktop is displayed as soon as the directory is displayed. The directory scrolls by and DeskMate is reloaded before you have a chance to view the directory. You can, fortunately, make a batch file pause after executing a command with the command PAUSE. Add the PAUSE command to the end of the batch file, like this: DIR \TEXT PAUSE If you expect the directory to take more than one screen, add the qualifier /P to the DIR command; when the directory fills up the screen, DOS will pause and prompt you to press any key before displaying another screen. So, this batch file will display a directory in a manner you can view at your leisure: DIR \TEXT/P PAUSE *Adding Flexibility to Batch Files with Variables*. Now, what if you have frequent occasion to view more than one directory? Will you have to create a batch file for each directory? The answer to that question is "No." You can insert variables into batch files. Variables always begin with a percent sign (%) followed by a number, like this: %1, %2, %3, etc. When a batch file has a variable, DOS assigns whatever you type following the batch file name as the value of the variable. For example, if a batch file titled K.BAT contained the line: DEL *.%1 and you typed K BAK at the DOS prompt, the command would be interpreted as DEL *.BAK and all files with the extension .BAK would be deleted. It is possible to run a batch file with a variable from DeskMate. After entering the batch file name in the Run File list box's "Program:" edit field, enter the desired value for the variable in the "Data File:" edit field. For instance, to make the example batch file K.BAT delete all files with the filename extension .BAK, you would enter K in the "Program:" edit field and BAK in the "Data File:" edit field. Returning to our DIRTEXT batch file example, if you put a variable as the filename specification, you'll be able to view a file listing of any directory you specify in the "Data File:" edit field. Here's how the batch file would look: DIR \%1/P PAUSE Notice that the only change is the substitution of %1 for TEXT, and that the pauses have been retained. (You might want to use another name for the file, though--perhaps DI.BAT.) *Creating a List Box to Run Batch Files*. You can also create a list box to run some batch files--only those without variables. Create a list box with an appropriate menu title (perhaps BATCH), specify the data file extension as BAT, and make the startup directory your DeskMate disk/directory (the floppy disk with which you start DeskMate, or with a hard disk the directory \DESK or \DESKMATE, depending on your version). This will create a list box that displays all files with the extension .BAT. When you want to run a batch file from the list box, simply select the file from the list. (You cannot use variables because list box operation makes no provision for adding variables when running a program.) There are several applications for a batch-file list box. You can put some specialized DOS-command batch files in the box and give it the menu title "UTILITIES." You might include batch files that copy all data files to a backup disk, change to specific directories, or which run utility programs such as the Norton Utilities. Or, you might title the box PROGRAM2, and include batch files that start non-DeskMate programs. Why? Well, if you wanted to have all non-DeskMate programs available (.COM and .EXE files) on the desktop via list boxes, you might create one list box with COM as the data file extension, and another with the EXE as the designation. That's fine, except you've added two list boxes to the desktop. You can combine the functions of list boxes for both COM and EXE files into one by creating a batch file for each of the programs you'll want to run (with or without data file specifications or qualifiers). *Where to Keep Batch Files*. Unless you've used the SET PATH option in your boot disk's or hard disk's AUTOEXEC.BAT file, batch files you intend to use should be in the DeskMate directory. Otherwise, you'll have to specify a directory when you enter the name of a batch file in the Run Program dialog box. If you've used the SET PATH option, as described in Chapter 5, DOS will look for the batch file first in the current directory, and then in the directory specified with SET PATH. In this case, it is best to keep all batch files in the specified directory. *Batch File Rules* When creating batch files, follow these general guidelines: * Don't give a batch file the name of a .COM or .EXE program that resides in the same directory as the batch file; DOS will run a .COM or .EXE program before it runs a batch file. * Do not give a batch file the name of a DOS command; as with program names, DOS will recognize and act on the command rather than the batch file. * Use only legitimate DOS commands in a batch file. * You can create a batch file using any text editor that produces standard 7-bit text, including Text. Remember to not put a carriage return after the end of the final line in the file (don't press ENTER). If you use Text to create a batch file, use the Save as... option on the File menu to save the file with the extension .BAT. *Special Notes on Running Batch Files from DeskMate* You should always run batch files from the desktop; if you run a batch file from an application's File menu, unpredictable results may occur. Also, the file DMOLDAPP.MOD may be required if you use Task Switch to move to the desktop in order to run a batch file. To avoid conflicts with some system configurations or certain versions of DeskMate, make sure a batch file ends at the end of the final line. Do not press ENTER before pressing F6 after typing the final line of the batch file. Always press F6 at the end of the final line in the batch file, and then press ENTER. Finally, if you wish to stop a batch file while it is running, enter Ctrl-Break (hold down the Ctrl and Break keys simultaneously). The batch file will pause and ask whether you want to discontinue the batch operation. # You can create batch files to do almost anything you can do from DOS--run programs, view lists of files with specific filenames or extensions, delete or copy files with specific filenames or extensions, etc. Table 15.1 provides examples of a number of different kinds of batch files. (Table 15.1 here) Table 15.1 Sample Batch Files *DESKMATE DATA EXCHANGE* If you have been using other programs that duplicate DeskMate's applications, you will probably want to use the data in those files with DeskMate. You can "import" and "export" data from and to other software, but only to a limited extent, as described in Chapter 15 of GETTING THE MOST OUT OF DESKMATE 3. Copyright, 1989, 1990, Michael A. Banks All Rights Reserved Interested in modem communications? Check out THE MODEM REFERENCE, also by Michael A. Banks and published by Brady Books/Simon & Schuster. Recommended by Jerry Pournelle in Byte, The New York times, The Smithsonian Magazine, various computer magazines, etc. Want the lowdown on getting more out of your word processor? Read the only book on word processing written by writers, for writers: WORD PROCESSING SECRETS FOR WRITERS, by Michael A. Banks & Ansen Dibel (Writer's Digest Books).