The magazine of the Melbourne PC User Group

The DOS PATH - For Beginners
Tom Coleman

One of the fundamental things about using DOS is that (NOW REMEMBER THIS) the first thing on the command line is a command. The command line is whatever you type at the DOS prompt. If what you have typed is not recognized as a command by DOS then you will get a "Bad Command or File name" error message. This error message is telling you is there is something wrong with the first thing you typed in.
 
The first thing on the, command line is the first character or string of characters up to the first separator. For most purposes a separator is a space but DOS also considers / , = , - and a few more as being separators too. There are a few forbidden characters too. Have a look in a DOS manual to find out more about them.

OK, so what are the DOS commands? It helps to know that there are two types of DOS command. One type is loaded into the computer when you start up; they are loaded into the computer's electronic memory and the computer just knows them, always. Well always at the DOS prompt, anyway. This type of command is called an internal Command. Many of the frequently used commands are internal. For example, COPY, DEL, CD, DIR and a bunch of others are always understood when you enter them.
 
Mind you, just typing COPY and pressing <Enter> is a bit like jumping into a taxi and saying "GO" to the driver. The COPY command requires more information to know what to copy and where. This extra information appended to a command is called a parameter and there is a whole bundle of them. This implies that you need to have some idea of what you want to accomplish when using the command.

Let's take a diversion and give the pot a stir.

Regardless of whether you are using the DOS interface or the Windows interface you still need to have some idea of what you want to accomplish. DOS does not tempt you with things to click on. Either you know the appropriate command or you look it up in the manual - or you just can't do it. When using Windows you can get sucked into clicking here and there without really knowing what you are doing, often being given choices you do not understand. On the other hand Windows enables you to do all sorts of things when DOS cannot. eg. you cannot tag files in DOS. Generally you should use the right tool for the right job and both DOS and Windows have their strengths. DOS is still the fastest kid on the block but most programs these days are written to run in Windows and that is what you should use when the occasion demands.

Back onto course now and this business of commands. We have mentioned the internal commands, so pretty obviously the other type of command is going to be the external command. The external command is also typed at the DOS prompt, but it actually runs a program file. There are a swag of these programs that come with DOS. FORMAT.COM is one and FDISK.EXE is another (both extremely dangerous in the wrong hands). There are plenty of these external commands. You can look them up in the \DOS directory if you are using pure DOS (6.22 or earlier). In Windows they are shared between the \Windows and the \Windows\Command folders. To execute these commands means to run the programs. You type the name of the program file and it will be run. Quite reasonably the computer must be able to find the file in order to run it and that's where the DOS PATH comes into play. Another thing to note; not all files are executable. That is, not all files are program files.
 
Let's Do Another Sidetrack. Broadly speaking there are three categories of file on your computer. They are files that contain:
  • INSTRUCTIONS TO THE COMPUTER
  • INFORMATION FOR USE BY A PROGRAM
  • DATA CREATED AND/OR STORED BY A PROGRAM.
T he first category is what concerns us here. Not all instructions are DOS instructions. Your word processor, your games, any application program (ie. one written for a specific purpose) can and will give instructions to the computer. However, regardless of whether it is an application program or a DOS program, there are only three varieties of file in the first category that contain INSTRUCTIONS TO THE COMPUTER. They are files with a COM or an EXE or a BAT extension. No others contain instructions.

Whilst DOS will execute the instructions contained in a batch file, there are no .BAT files that are part of DOS. The other two, the COM and the EXE files you can regard as being essentially the same. In fact the way the operating system uses them is very different, but the differences do not show at the user level. About the only difference as far as the user is concerned, is the priority given to each.
 
When you enter something on the command line, say ABC, and press <Enter> the computer looks first for a file with a .COM extension (ABC.COM) in the current directory. Then it looks for a file with an .EXE extension (ABC.EXE) and finally one with a BAT extension (ABC.BAT). As soon as it finds a match it stops looking and starts to execute the file. If you think about that you will realize that if you have two files with the same filenames but different extensions (COM, EXE or BAT), then only the highest in the sequence will ever be executed. Anyway, if it fails to find a match in the current directory it then goes off and searches elsewhere. It searches through every directory listed in the DOS PATH, and that's a variable stored in an area of memory known as the DOS Environment.

Never mind about Environment and variables; you can either look it up or ignore it for now because we are interested in only one of them, and that is the PATH variable.

If you want to know what's in the PATH variable then go to the DOS prompt and type in PATH and press <Enter>.

A quick recap:
  • PATH was the first thing you typed on the command line, so it must be a command.
  • You will not find a PATH.COM, PATH.EXE or a PATH.BAT so it must be an internal command.
T he output of the PATH command will vary from one computer to another but it might look like Figure 1 below.


Figure 1. A typical DOS PATH

The parts or elements of the line are separated by semicolons (;) so that the first element of the Path is C:\Windows and the next is C:\Windows\Command with the last element being C:\Vet.

I will be talking about Folders and Directories soon. Remember these two terms mean the same thing and are interchangeable. In DOS we usually talk about Directories and in Windows we call them Folders.

If DOS cannot find ABC anything in the current directory then it goes to the first element in the Path (C:\Windows) and it starts to look there for the same files in the same order. If it fails to find what it's looking for then it looks in the second element (C:\Windows\Command) and if that does not produce any result then it looks in the next element and the next, and the next, until it has looked in all of the elements in the Path variable. It then gives up and issues a "Bad Command or File name" error message.

Now I must confess that I have not told all of the truth. You see, before DOS goes off looking for COM, EXE and BAT files it checks to see if the command is either a DOSKEY macro or a regular internal command. Don't worry about DOSKEY macros, they will come later, unless you get curious then you can look them up in the manual. Sometimes the DOS tips and tricks books are better than the manuals.

Generally books come as either reference works or tutorials. Once you know the subject you do not need a tutorial but they are usually terrible references. Buy what you need. References are not much use until you know the subject.

Do not bother trying to learn DOS as a theoretical subject. You will not learn much. Have a use for it. Computing is a practical skill; like sex, the theory is interesting and some people can talk up a storm about it, but it is the practical that determines whether you are any good at it.

Reprinted from the July 2002 issue of PC Update, the magazine of Melbourne PC User Group, Australia

[About Melbourne PC User Group]