|Note:||The following text applies to COMMAND.COM (MS- and PC-DOS, Windows 9*/ME), not to CMD.EXE (NT, 2000, XP, Server 2003), except where stated otherwise.|
The PATH is an environment variable containing a list of directories, separated by semi-colons (;). It is used by the command processor to find the programs or executables it needs.
The PATH variable can be set in two ways:
In the first case, using
SET, the PATH variable is set to
c:\bat;c:\dos, in lower case, as specified.
In the second case, using
PATH, the PATH variable is set to
C:\BAT;C:\DOS, in upper case, no matter how it was specified.
This feature may be used when checking command line parameters which may be given in any combination of upper and lower case (in MS-DOS 7.*, use FOR if the command line parameters to be checked are preceded by forward slashes; see the interactive examples; and use IF /I or my UPCASE.BAT for NT):
SET OLDPATH=%PATH% PATH %1 IF "%PATH%"=="PARAMETER" GOTO OK ECHO Parameter does not match GOTO Continue :OK ECHO Parameter OK :Continue PATH %OLDPATH%
Keep in mind that you need enough free environment space to store the OLDPATH variable. Since PATH variables tend to be long strings, you might run out of environment space when setting OLDPATH to %PATH%, in which case you have no way to restore the original path afterward.
The following code stores the original PATH in a temporary batch file instead of in environment space:
PATH > TEMP.BAT PATH %1 IF "%PATH%"=="PARAMETER" GOTO OK ECHO Parameter does not match GOTO Continue :OK ECHO Parameter OK :Continue CALL TEMP.BAT
This method poses another threat to your system's integrity, though: the command line storing the current PATH in TEMP.BAT may become too long for COMMAND.COM to handle — COMMAND.COM ignores character 128 and further from any command line.
Besides that, you cannot be absolutely certain that you can write TEMP.BAT in the current directory; but adding a full path to the TEMP.BAT file name — as in %TEMP%\TEMP.BAT — will make the command line even longer.
Well, I never said it would be easy!
If you do not plan to change the PATH during a (DOS) session, and you need a long PATH, consider setting the PATH in CONFIG.SYS (using
SET PATH=....) instead of AUTOEXEC.BAT.
Remember, it is COMMAND.COM that poses the 127 character limit on command lines, not DOS. And COMMAND.COM is given control only after CONFIG.SYS is executed.
So by setting the PATH in CONFIG.SYS there is practically no limit to the length of the PATH, except environment space.
When memory is at a premium, consider this: each and every TSR, when loaded, keeps a copy of the environment in memory. So you may save some memory by setting environment variables — including PATH and PROMPT — after loading TSRs.
|page last uploaded: 2015-08-24, 21:13|