The DOS command PATH is a useful but poorly understood part of DOS. It is a command that produces a listing of the current path if it is entered on its own. Entered with appropriate parameters it sets the path. OK, so just what is the Path anyway. The Path is where DOS goes to find .COM .EXE or .BAT files (ie Commands) that are not in the current directory. That could do with a bit more explanation so, for the purpose of this discussion, we will use the Path on my machine. The Path on my machine is: C:\Belfry;C:\Util;C:\Dos Examine it. It is three subdirectories including the drive letter, each separated by a semicolon. Sometimes I see a Path that does not include the drive letter for each of the subdirectories. Generally it seems to work. However what happens is that the current drive is substituted for the missing drive letter. If you happen to be in drive A: then it looks for the subdirectortes in drive A:. If you are in drive C: then it looks on drive C:. It works because most paths are set to subdirectories in drive C: and most users spend most of their time in drive C:. It fails in any other drive. To see where the Path fits in to the overall scheme of things let's take a look at what happens when you type something in at the DOS prompt and then press Enter. You might type: Copy a:\*.* C:\Batutil On the other hand if you were in a hurry or have fat fingers you might type: cvopyu a:\*.* C:\Batutil It makes no difference to DOS. It handles all commands the same way. So far as DOS is concerned: The First Thing On The Command Line Is A Commend. Once you press Enter, DOS looks at what you typed. First it numbers each group of characters starting at zero. This is useful to know for batch file writers but is not part of this discussion and will not be mentioned again. DOS then takes the first group of characters and begins looking for a match. The first place it looks is in the Environment. That is where a number of Environment Variables are stored. Usually these are COMSPEC, PROMPT and PATH but you can add many more if you need. Failing to find a match in the Environment DOS will go and have a look in COMMAND.COM. That's where DEL, COPY, DIR, TIME and all of the INTERNAL COMMANDS are stored. In our sample command a match would be found for COPY and DOS would then execute the appropriate instruction. If we have been fumble fingered as in the alternative example, DOS will now look through the current directory looking for a .COM isle with a name to match the command. In our case it looks for CVOPYU.COM which it will probably not find. That being the case DOS then goes through again looking for a similarly named .EXE file and, if it still cannot find a match, goes through again, this time looking for a .BAT Me. It is worth taking a brief diversion here. If you have a two files with the same name but different extensions of .COM or .EXE or .BAT then only the first one in that order will ever be executed. DOS searches for a match in that order and stops looking when it finds the first match. In the case of our typo it is not likely to find a match so DOS now goes and looks to see what the PATH contains. DOS then goes looking for a .COM then a .EXE then a .BAT file in each element in the Path. In the case of the sample Path DOS would first look in C:\Belfrey where I keep my batch files. Then it would look in C:\Dos and finally in C:\Util. If at any time it finds a match, it stops looking and starts to execute that file. If it fails to find any match, it prints the message BAD COMMAND OR FILENAME. Now that you know where the Path fits into the overall scheme of things, there are a couple of items that you should notice. First, only .COM .EXE and .BAT are looked for so its no good looking for data files. Next if you have files with the same name in different subdirectories in the Path, DOS stops looking when it finds the first match so the second can never get found. You will have to change the name of one of them. A misconception some users have is that every parent directory of each subdirectory in the Path is searched. This is not so. Only the Belfry, Dos and Util subdirectories are searched in the example given not the root directory as well. All this might be edifying or mystifying depending on how useful all this is to you. So! How do you use it? You usually set your PATH with a line in your AUTOEXEC.BAT You can enter another Path command any time you like at the DOS prompt but the usual thing is to set it up once and for all and then forget about it. Autoexec.bats are good for that kind of thing. Just a brief reminder that the AUTOEXEC.BAT is just and ordinary batch file with the exception that it is automatically executed at start-up time. You could, if you wished, execute it from the command line any time you liked, but I cant think of many reasons why you would want to. Just add the line PATH=C:\DOS;C:\UTIL etc etc There is no need for a semicolon at the end. Actually there is no need for the equals sign either. A space will do just as well. It is prudent to put the PATH command early in the Autoexec.bat so that the Path is set for subsequent commands. Until you set the Path there is no path so you must put in the full file spec for anything that comes before the Path command or have the file in the root directory. This includes items in the CONFIG.SYS. As it was indicated earlier, the Path is usually set once and then forgotten but what do you do if you want to temporarily change or add to the path. You can try a number of ways depending on what outcome you want. For instance you might want to use some utility files on a floppy in drive A: instead of the files in C:\Util. Heres a trick to save your current path. Just entering the word PATH at the DOS prompt gives you the current Path. In the case of our example it would be PATH=C:\BELFRY;C:\DOS;C:\UTIL Now by coincidence that is also the form of the command to create that path. So if you use redirection and use the output of the Path command as input to create a batch file thus:- PATH PTH.BAT you will create a file called PTH.BAT with the above Path command in It. You can now change the Path to anything you like and restore the old one lay executing PTH.BAT So you can then issue the command PATH=A: to set up the new Path. The disadvantage of this is that you lose the C:\Dos and C:\Belfry elements of the path also. If you want to keep them then you must either type in the whole new Path command or better still make up a batch file with the new path in it Then you can swap between the original path and the modified path by executing one or the other batch file. To do this you create PTH.BAT as outlined above and then using exactly the same method you create another batch file with different name. For example PATH APTH.BAT So you now have two batch files with the same command in them. Now edit the second one to your modified Path. It might be PATH=A:\;C:\DOS;C:\BELFRY It would pay to put both of these batch files in a subdirectory common to both Path commands so that you can always execute them from anywhere. Now you can swap between Paths at will. If all of the above is a bit much you can just change the Path and then restore the old one by executing the Autoexec.bat from the command line. You do that by changing into the root directory and typing AUTOEXEC at the DOS prompt. This is quicker than rebooting but might be an inconvenient thing to do. Of course you could always write a batch file that offers you a selection of several different Paths and lets you choose one. I might do an article on that shortly. Meanwhile you can have a go. Reprinted from the March 1992 issue of PC Update, the magazine of Melbourne PC User Group, Australia |