Printer Friendly

Simplify humdrum PC tasks with batch files.

Batch files, a series of MS-DOS commands that can be repeated whenever needed, help MS-DOS automate routine tasks. They work well for jobs that would otherwise be slow or confusing. File backup, file deletion, data archiving, and adjusting printer settings are a few that come to mind.

The two types of batch files are those that work automatically and those that must be called up when desired or can be incorporated into other batch files to run "semi-automatically."

* Autoexec.bat. Batch files that you want to run every time you turn on your computer are named AUTOEXEC.BAT. Because the file lets you set up your system as desired, include the commands that will fit your needs.

A PROMPT command in your autoexecuting program changes the familiar A> or C> prompt to one that provides more information. I use a prompt that replaces the drive designation with the name of the directory I am using. Prompts may include the date, time, DOS version, or a special message. Look in your DOS manual for the codes to use with the prompt command of your system.

A PATH command lists the directories and subdirectories on the hard drive. This command instructs DOS to search all listed directories for a particular program or file. An important limitation of PATH is its briefness; it can accommodate no more than 127 characters. Directory and subdirectory names must be planned around this limit. DOS searches for files in the order in which their directories are listed in the PATH statement. Therefore, place the directories you will use most often at the top of the list.

DOS programs can be included in an autoexecuting file. Possible commands to use include DATE and TIME, which are particularly important if your system lacks a clock with a battery backup.

Useful commands in the autoexec file include FASTOPEN, VERIFY, CHKDSK, ASSIGN, and RAM-DISK. In addition, you can use DOS internal commands, such as CLS, COPY, and TYPE, as described in your DOS manual.

Load any memory resident software that you routinely use, such as Sidekick or Superkey (both from Borland International, Scotts Valley, Calif.).

Installing certain commercial programs will automatically modify the autoexecuting program. Some programs display prompt commands asking for your go-ahead each time. In any case, always review your autoexecuting file after installing new software to be sure it is set up to work the way you want.

Batch files are not case sensitive. Either uppercase or lowercase letters will work in naming and calling files throughout.

In the autoexec program displayed in Figure I, the CALENDAR command and the parameters that follow on the same line load a memory resident program that will put a monthly calendar on the screen when a hot key combination is pressed. CALENDAR is one of the Baker's Dozen utilities (Buttonware, Bellevue, Wash.), available from most shareware sources.

The FASTOPEN command and its parameters load a DOS program that speeds the opening of files. The ECHO OFF command instructs the computer not to print commands on the screen. CLS clears the screen. PROMPT $P$G changes the prompt to the name of the current directory followed by the "more than" symbol (>). The PATH command specifies which directories will be searched for commands. Then the TYPE MENU .PIC command prints a file called MENU.PIC on the screen.

* Do-it-yourself files. The other type of batch file runs on command to perform many routine computing tasks. These files, which make use of standard MS-DOS commands, run when their names are typed at a prompt or included in another batch file.

Most persons who use computers take advantage of a few programs, often a word processor, a spreadsheet, possibly a database, and a few special applications. Once they have all been stored on a hard disk in separate directories, simply remembering the command line that will call them up can be a chore. While menu programs to automate the selection of programs are available commercially, it is just as easy and much cheaper to use batch files run on homemade menus instead.

To streamline the process, you can use the program names of software as file commands; for example, LOTUS for Lotus 1-2-3 (Lotus Development Corp., Cambridge. Mass.), WP for WordPerfect (WordPerfect Corp., Orem, Utah), and ACCESS for Symphony (Lotus Development Corp.).

These hard disk menu programs are built around an ASCII text file called MENU.PIC. This short file consists of a numbered list of the programs that are routinely used. In the example shown, each program on the menu has been assigned a number corresponding to a batch file--1.BAT, 2.BAT, and so on. Typing one of the numbers evokes the corresponding batch file, which automatically calls up the proper directory and starts the program.

Other naming schemes, such as the first letter of the program name (e.g., W.BAT for a word processor), would work just as well. In some cases the batch file can return to the root directory and recall the menu when it's time to start working with another program. Two sample batch files do this.

* Copying. Batch files will automatically copy specific programs such as the one shown in Figure IV. I designed this program to make distribution copies of a cost accounting system described in a previous issue of MLO and offered to readers free of charge.(1) (The same offer holds true here. For details, see the information at the end of this article.)

First, the program copies all the BASIC programs from the source disk to a new disk. Then it copies two batch files and two text files to the new disk. Finally, it pauses to be sure the printer is on line; if so, it prints a letter. The advantage of this program was that it copied only specified programs while ignoring several data files in the source disk that were not needed on the distribution disks.

* Backup. It's a mistake to neglect backing up your hard disk regularly. In BACK.BAT, an automated backup program that uses batch files, all files in the hard disk that were named with a specific extension are copied to a floppy disk. The file pauses, prompts for a new disk, and repeats the process for files with other extensions until all the files have been backed up.

* Deletion. Batch files can be tailor made to automate file deletion. In an autoexecuting file on one of my computers, I included the line DEL *.BAK, which deletes all files with the extension .BAK. These backup files are produced automatically by some text editors and should be deleted routinely.

Alternatively, automatic deletion programs can be run after backup of the hard drive has been completed. In such cases the batch file would list the extensions of files to be deleted while leaving program and other files untouched.

I am planning to use a batch file to load a terminal emulation program that will capture data on quality control and workload from our laboratory information system. Batch files would work equally well to load a personal information manager (PIM) program such as Agenda (Lotus Development Corp.), IZE (Persoft, Madison, Wis.), and Memory-Mate (Broderbund, San Rafael, Calif.). Batch files are ideal for recording dialing parameters that can be associated with communications programs. I have used batch files to load and run a laboratory staff scheduling program and the Abbottbase (Abbott Laboratories, North Chicago, Ill.) trending program that charts changes in patient status as reflected in carcinoembryonic antigen (CEA) assays.

One good source of ideas batch files is the monthly Hot Tips column in PC Computing magazine. In recent issues this column has described batch files to change printer ports, run a timer program, run a shutdown routine, and run programs from an autoexecuting file at preset intervals.

Batch files are ASCII text files. Their names must include the extension .BAT. Batch files can contain standard DOS commands, batch file commands, and program names. DOS manuals list the appropriate DOS and batch file commands to use. External DOS commands such as CHKDSK and FORMAT must be in the directory you are using or in one listed in your path statement.

Batch file commands include a subset of DOS commands that are usable only in batch files. Simple batch file commands include ECHO, which controls printing to the screen; PAUSE, which stops program execution until a key is pressed; and REM, which allows comments to be included in the batch file for documentation.

Other batch file commands are used to control the steps used in a program. These include GOTO, IF EXIST, IF NOT EXIST, FOR...DO, and ON ERRORLEVEL, among others. In each case the command allows the batch file to branch to subroutines located inside it.

Within batch files are variables called replaceable parameters. Unlike most programs, batch files are not interactive. In order to be used in running a program, the replaceable parameter must be listed after the batch file name. While any number of parameters may be listed, only nine can be used at one time. In the batch file these parameters are represented by a percent sign (%) and a number from 1 to 9. The first parameter is always number 1, the second is 2, and so on. The SHIFT command drops the first parameter and moves up others in the list.

Subroutines in batch files are symbolized by a colon and a name. Typing a GOTO statement will enter a subroutine in the batch file.

* BACK.BAT. The BACK.BAT program at right illustrates several such commands. The program is used to back up data from a hard drive to a floppy disk. To run the program from the prompt, you would type the program name, list the file extensions to be backed up, and END. For example, BACK WK1 PIC PRN END would be used to back up a Lotus 1-2-3 directory.

The command CLS clears the screen; ECHO OFF stops other commands from printing to the screen. The REM line documents how to call up the file. :COPIER is not a DOS command but the name of a subroutine. The following line states that if no file exists with the extension listed in the parameter line, the program should proceed to the subroutine labeled :NEXT.

The entry COPY *.%1 B: copies all the files with the specified file extension to a disk in the B: drive. ECHO prints a message on the screen. PAUSE causes the program to stop running until any key is pressed to continue. :NEXT is a subroutine that uses SHIFT to look at the next parameter on the command line.

The IF statement sends the program back to the copier subroutine if the parameter has not become the word END. In the final subroutine, the ECHO ON command is used to restore the printing of DOS commands as before.

Because batch files must use the ASCII format, the characters in the file are coded according to the standard method. ASCII text files can be created in several ways. Files produced with Edlin, the line editor included with MS DOS, are created in ASCII for mat. Every word processor I have used has been able to save text in ASCII. WordPerfect, for example, uses the Text Out option for this. In addition, simple line editors are available from shareware sources. I found the one I use, TED (Text EDitor), in PC Magazine several years ago.(2)

1. Sehloff, J. Computer filing: How to save data on disk. MLO 20(11): 81-83, November 1988.

2. Kihlken, T. The tiniest editor you'll ever need. PC Magazine 7(19): 281-322, Nov. 15, 1988.

General reference:

Richardson, R. "MS-DOS Batch File Programming, Including OS/2." Blue Ridge Summit, Pa., TAB Books, 1990.

Figure I

AUTOEXEC.BAT An autoexecuting program

ECHO OFF calendar i = cal.dat r = y fastopen c: = 10 CLS prompt $p$p PATH = \;\DOS;\lotus;\symphony;\wp51;\abotbase;\pcfile;\lotus\allways type menu.pic

Figure II

MENU.PIC An ASCII tex file

1. DOS & Basic programs 2. Lotus 1-2-3 3. Symphony 4. WordPerfect 5.1 5. Abbottbase (CEA) 6. Merlin 7. Monarch demo 8. Schedule program 9. PC-File 10. Label printer

Figure III

Sample batch files





Figure IV

COPIER.BAT Batch file to copy a series of programs

copy *.bas b: copy setup.bat b: copy autoexec.bat b: copy readme. b: copy manual.txt b: echo off echo Be sure that printer is on Pause type letter.txt>prn echo All Files Copied echo on

Figure V

BACK.BAT An automated backup program

CLS ECHO OFF REM Enter extentions to be backed up, END as last parameter :COPIER IF NOT EXISTT *.%1 GOTO NEXT COPY *.%1 B: ECHO You may change disks in drive B: if desired now PAUSE :NEXT SHIFT IF NOT % 1 = = END GOTO COPIER :END ECHO ON

James A. Sehloff is LIS coordinator at Holy Family Memorial Medical Center, Manitowoc, Wis.
COPYRIGHT 1991 Nelson Publishing
No portion of this article can be reproduced without the express written permission from the copyright holder.
Copyright 1991 Gale, Cengage Learning. All rights reserved.

Article Details
Printer friendly Cite/link Email Feedback
Title Annotation:personal computer
Author:Sehloff, James A.
Publication:Medical Laboratory Observer
Date:Sep 1, 1991
Previous Article:Managing the transition to a certified toxicology lab.
Next Article:Meeting the special needs of the open heart surgery patient.

Related Articles
Micro-to-Mainframe Links Are Forged by Stream of Products.
Microcomputer security and control: six inexpensive and simple techniques.
Simplified use of batch files.
Lotus 1-2-3 data entry made easy with a macro.
One-button backups: creating a batch file is as easy as ...
Productivity applications.

Terms of use | Copyright © 2017 Farlex, Inc. | Feedback | For webmasters