The magazine of the Melbourne PC User Group

A Path for Beginners
Tom Coleman

Lately I have come across a number of horrendous PATH statements. Let's take a look at one.

PATH=C:\;C:\DOS;C:\WP51;C:\TEMP;C:\NORTON;C:\UTIL;C:\QUICKEN;C:\GAMES;C:\PARADOX;C:\WINDOWS; C:\WINDOWS\BIN;C:\GAMES\GAMES;C:\XTREE;C:\TELIX

Does yours look anything like that? First, let's look at where PATH fits into the overall scheme of things and then take a look at what is wrong with this particular one, and many other PATH statements I see from time to time.

When you enter something on the command line (that is, at the DOS prompt), for example:

XCOPY *.* A:\  /M

DOS looks at the whole line and gives each part between separators (in this case, as in most, the separators are spaces) a number starting at 0. In order that it can identify what the numbers mean it puts a "%" in front of each number. Nothing to do with percentages, just an identifier.

Thus, "%1" is the "*.*" and "%2" is "A:\". We can use the "%" identifier in batch files, but that is outside the scope of this discussion. The bit we are interested in is %0, the first item on the command line.

How about we take a brief pause here and all repeat after me
The first thing on the command line is a command.

Now off you go for five minutes meditation on this simple mantra.

Doubtless you will have been enlightened if you followed the above instructions. You will now realise that "Bad Command or Filename" means there was something wrong with the first thing on the command line when you pressed the <Enter> key.

This raises the question, how did DOS know there was something wrong? The simplest answer is to follow DOS through as it tries to execute a command.

For the purposes of illustration we will enter a meaningless command. You can try it if you like.

I am going to enter the command, QQQ, which is pure garbage on my computer. DOS dutifully scans the line, takes the first thing on it (QQQ), and tries to execute it.

First it looks in the environment to see if it matches any of the variables in there.

The environment is a bit of conventional RAM (memory). It's part of your 640 kB, that holds a number of variables like PROMPT, COMSPEC, PATH, TEMP, and so on.

Failing to find QQQ there, DOS now takes a look in a bit of memory used by DOSKEY if you have it loaded. If it is a DOSKEY variable then it gets interpreted and executed. I don't have one called QQQ.

Now DOS takes a look at the current directory. You know, all the files that get listed when you type DIR. It looks first of all for a file named QQQ.COM. Failing to find it, DOS then goes looking for a file in the current directory named QQQ.EXE. Still no joy, so it has another look, this time for a file named QQQ.BAT.

Everybody stop. Now read that last paragraph again. Look at what has happened. DOS looked first for a .COM file, then for an .EXE file, and finally for a .BAT file. Most important.

Suppose I had files named QQQ.EXE and QQQ.BAT in the current directory and, to make life difficult, I wanted to execute the file, QQQ.BAT. It can't be done. QQQ.EXE is found first and then DOS stops looking.

Aha, you say, how about we put QQQ.BAT on the command line. Shouldn't that find it? Sorry. When DOS looks at the command line it sees the dot and tosses it out along with everything that follows it up to the next separator. In other words, the dot and extension are dumped before anything else happens.

What this means is that putting a file extension in the command is always a waste of time and is bad technique.

Having looked for the QQQ in the current directory and not found it DOS now goes looking for other places to search. Those other places to search are contained in the PATH statement.

If you examine the PATH statement at the beginning of this article you will see it consists of a list of directories separated by semicolons. DOS searches every item on the list of directories for, first, a COM file, then an EXE file, and then a BAT file. In our case, one called QQQ. Finally, when it has exhausted the list of directories in the PATH, DOS displays the message "Bad Command or Filename", and starts sulking. Even without having the latest versions of software, there is likely to be well over 10 MB of files searched on each occasion you make a typo.

Remember, there are only two or three executable files in each directory and none are files you are likely to want at a moment's notice. Often when there are many directories, there is a good chance you will execute a file of the same name in an earlier directory.

I remember one class I was running when we all had a jolly time trying to bail out of installing WordPerfect - I had forgotten to tell the students to change to drive A: before entering INSTALL. Talk about a thieves' picnic. We ran a bit overtime that night.

The argument that you need to be able to get access to, say, your word processor, at any time, really does not hold up when balancing the penalties of having it in the PATH against the advantages of writing a batch file to do exactly the same thing.

All you can do from the command line is execute the word processor. If you want to move, say, the dictionary into a RAMDISK to speed things up, it must be done manually each time. It could be done in the same batch file that starts the word processor, as well as automatically copying a custom dictionary back to drive C: when you have finished. It guards against forgetting, too.

All you need is a special directory to hold all your batch files and put it in the PATH. That way you can always find it. Take all your application programs out of the PATH and write batch files to start them.

Another thing about that PATH statement. Why on earth is the root directory there? The only things you should have in the root directory are COMMAND.COM, CONFIG.SYS, and AUTOEXEC.BAT. You may have some bloody-minded program that insists on writing its log file to the root directory, but generally the root directory should be clean, bare, and bald.

So just what should be in your PATH statement? Think about it. You want the files that you need to be able to access at any time from anywhere. Your DOS files, so C:\DOS should be in the path. I have suggested a directory for your batch files, so C:\BAT would be appropriate.

Then there is a bundle of utilities like LIST, and MEM, WHEREIS, and a bucket of others that are handy to have around. Put them all in a UTIL directory and put C:\UTIL in the PATH.

That's it. You don't need anything else.

The only decision now is which order do you put them in. The rule is to put the most frequently used directory first and the least frequently use directory last. Exactly which is most and which is leas is a reflection of how you choose to use ; computer, and that is up to you.

Reprinted from the September 1993 issue of PC Update, the magazine of Melbourne PC User Group, Australia

[About Melbourne PC User Group]