Choosing the right path. (Introdos) (Column)
by Tony Roberts
Control your PATH, and your computer will be faster and more efficient.
The PATH statement is an integral part of your computer's operating system. Know its secrets, and it can make your system work much faster and more efficiently.
If you have trouble understanding the PATH statement and why it's there, consider this real-world example.
I have the habit of setting my car keys in only three places: on my desk, on my dressing table, or on a certain kitchen shelf. When I'm ready to go motoring and my keys aren't in my pocket, I check my desk, my bedroom, and the kitchen; 99 percent of the time, the keys turn up. By following my path, I can quickly achieve the required result.
DOS's PATH statement is similar: It describes places on your system that are most likely to hold excutable files. Type a command at the DOS prompt, and the system checks the current subdirectory and then each of the subdirectories listed in the PATH to try to find the program you want to execute. By limiting the search path, you prevent the system from churning through the whole disk.
One of the problems with PATH statements, however, is that they tend to outgrow themselves. Prior to DOS 6, the PATH statement was limited to 127 characters. When you install software, the program often suggests that you add its subdirectory to the PATH statement. Eventually, the PATH line becomes too long and is truncated.
The major benefit of having a subdirectory in the PATH is that any program in that subdirectory can be executed from anywhere in your system without your having to enter the full path name. But the problem with a long PATH statement is that every time you execute a command, the system looks through all the subdirectories listed in the PATH; a long list can slow things down.
The best solution is to be stingy about what you put in the PATH. In most cases, include only subdirectories that must be available on a system-wide basis--DOS and Windows subdirectories for example. Also, create a BATCH subdirectory and put it on the PATH.
For all of your software, create a startup batch file in the batch directory. Have the batch file CD (Change Directory) to the appropriate subdirectory, and then start the application. Finally, upon termination of the application have the batch file CD back to the root directory.
This system allows you to start any program with a simple command, and it allows the system to find and execute commands more quickly.
You've probably noticed the double dot.(..) entry that appears when you ask for a directory listing of a subdirectory listing of a subdirectory. This entry represents the parent of the current subdirectory If you place the double dot entry in your path, you can start programs from the parent of whatever subdirectory happens to be current.
This can be useful strategy if your hard disk data is structured properly. Some people install programs in one subdirectory and then store data in a subdirectory one level below the program. For example, if your word processor is in C:[unkeyable]WORDP, you might keep your document files in C:[unkeyable]WORDP[unkeyable]DOCS. With the double dot entry in the PATH, you could always start the word processor while the WORDDP[unkeyable]DATA subdirectory was current. The same holds true for spreadsheet, database, and other data.
The PATH entry might look like this: PATH C:[unkeyable];C[unkeyable]DOS; C:[unkeyable]WINDOWS;..; C:[unkeyable]BATCH
If you use Windows, you've surely discovered that a lot of Windows software wants to be on the path. If you take it off, it just doesn't work right. But why have all those have all those huge subdirectories on the path when you're working from DOS?
The solution is to use two paths, one for DOS and one for Windows Start Windows from a batch file that toggles between the two path statements for you. Here's how it works.
If you type path at the DOS prompt, DOS will show you the current path statement. The sample batch file fragment below uses the DOS redirecton technique to copy the current PATH statement to a batch file. Then a new path, which points to Windows software, is established, and Windows is run. When you leave Windows, the system returns to the root directory and calls the batch file that was created by the first line of the program. Because that file contains an image of the previous PATH statement, the original PATH parameters are restored.
PATH > C:[unkeyable]BATCH[unkeyable]OLDPATH.BAT PATH C:[unkeyable]WINDOWS:C[unkeyable]ALDUS; C:[unkeyable]PM4:C:[unkeyable]EXEL;C:[unkeyable]DESKSCAN C:[unkeyable]WINDOWS[unkeyable]WIN %1 %2 %3 %4 C: CD[unkeyable] CALL C:[unkeyable]BATCH[unkeyable]OLDPATH
If none of this suits you and you own DOS 6, you can create PATH statements longer than 127 characters by including a PATH line in your CONFIG.SYS file. But once your long path is established by the CONFIG.SYS, you can't modify it from the DOS prompt or a batch file or it will be cut to the first 127 characters.