The Technofile Web site has moved.


Technofile is now located at http://twcny.rr.com/technofile/
Please update your links, bookmarks and Favorites.  
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
 

Batch files for newcomers, Part 1

technofile  by al fasoldt

Columns and commentaries in a life-long dance with technology
 

Simple gray rule



Batch files for newcomers, Part 1 


By Al Fasoldt

Copyright © 1990, The Syracuse Newspapers

The IBM PC was one of the best things that ever happened to computing. But the operating system IBM chose for its first personal computer a decade ago, MS-DOS, was one of the worst things that ever happened.

But we can't have everything, and so we have to live with DOS—at least those of us who have IBM-compatible computers and who don't have OS/2, the system that may someday supplant MS-DOS.

And that means that anything we can do to make Microsoft's disc operating system work better is just like buying time. And if we can do it on the basis of free or nearly free advice, we're getting something for practically nothing.

This week and at intervals in the months to come, I'll be offering that advice. I'm not doing it because I like MS-DOS; I'm motivated to pass on all these shortcuts because I hate the way DOS works—and I just love getting back at Microsoft by making DOS do all sorts of tricks.

Batch files, as you probably already know, are line-by-line lists of instructions to DOS. The most common batch file is AUTOEXEC.BAT, which your PC runs every time you turn it on.

A typical batch file for a computer that has a hard-disc drive might have these commands, among others:

ECHO OFF

CLS

SET PATH C:;C:\DOS;C:\MEMOS;C:\EXCEL;C:\WORDPROC

The commands do these operations: They hide themselves so they can't been seen on the screen ("echo off"); they clear the screen ("cls"); and they tell DOS to look in certain pathways any time you issue a command ("set path").

The path command is very important. It lets you run programs without having to know where they are—where, in other words, their pathways are.

For example, if you want to run WordPerfect, you don't have to move into the "WORDPROC" pathway first; just type "WP" and MS-DOS will search all the paths listed in your "set path" specification until it finds the program called "WP.EXE."

This is handy. But it's terribly inefficient for running a regular program, because you're forcing DOS to do a lot of searching each time you run the program.

Here's a better way. First, create a subdirectory on the "C" drive called "BATCH." (Make sure you are in the root or main directory of "C," and then type "MKDIR BATCH.")

Then change your path specification by editing your AUTOEXEC.BAT file so that the first entry is "C:\BATCH."

Now you're ready to create batch files for your regular programs. These batch files will run faster for two reasons—they'll be placed in the "C:BATCH" subdirectory, so DOS will find them right away, and they'll be written with the precise pathway as part of the command to DOS.

Let's create a WordPerfect batch file this faster way. Call it "WP.BAT" and make sure it is in the "C:\BATCH" subdirectory. In its simplest form, it has only one line:

C:\WORDPROC WP.EXE

So, when you want to run WordPerfect, you type "WP," just like before, but this time MS-DOS executes the program quickly. Why? Because it knew where to find it.

Want more? Here are a few more tips. They're all very easy.

MS-DOS lets you pass parameters in batch files. That is, it makes use of the percent symbol in front of a number from 0 to 9. It looks like this: "%1."

The "%1" stands for "whatever my master or mistress typed in when the batch file was launched." This gives you an amazing power. Here's an example of a simple batch file that will copy a file from whatever directory you are currently in to a floppy disc. It's C.BAT.

COPY %1 A:

(That's the entire batch file; just create it with a word processor and save it in ASCII form to your disc.)

Simple, yes? You run it by typing "C MYFILE"—with "MYFILE" being the file you want copied.

But you have %2 and %3, all the way to 9. They're just the things you typed second and third and so on. So you can make a batch file like this one, which I call MOVE.BAT:

COPY %1 A:

COPY %2 A:

DELETE %1

DELETE %2

You run this batch file by typing "MOVE ONEFILE TWOFILE" (with those two file names being anything you like). They are copied and then deleted.

Neat, eh? And you thought you'd never be a programmer, right? 


 Image courtesy of Adobe Systems Inc.technofile: [Articles] [Home page] [Comments: afasoldt@dreamscape.com]