Path

Index

The PATH command is used to view or modify the Path environmental variable and is synonymous with "SET PATH=".

When an executable file is named on the command line (or in a batch file) without an explicit path, Dos will always first search for this file in the current directory on the current drive. If the file is not found there, Dos will then search any paths listed in the Path environmental variable.

Syntax:

To set a path:
PATH path1[;path2...]]
or
PATH=path1[;path2...]]

To add directories to an existing Path environmental variable:
PATH %path%; path3[;path4...]]

To clear all path settings:
PATH ;

To display the current path settings:
PATH
pathx The full path to be included.
To include a directory name that includes a space, enclose either the whole path or just the directory in inverted commas (see Examples below).
a trailing backslash is optional: both path forms are recognized as valid

Notes:

  1. When Dos searches for a file, after first looking in the current directory, it looks through the directories in the PATH environmental variable in the order they are listed.

  2. If executable files in the same directory have the same name but different extensions, and the name is entered without an extension, Dos will run a ".com" program before an ".exe" and an ".exe" program before a ".bat" file.

  3. When a number of paths are listed, they must be separated by semicolons - but no spaces. If a space is included, a "Too many parameters" error message is displayed.

  4. If the Path environmental variable has been defined, a second instance of the PATH statement overwrites the first. To add a directory to the Path it is necessary to include all paths originally defined along with the new one. The simplest way to do this is to define the new path as "the contents of the Path environmental variable" (%path%) along with the new entries. There is no such shortcut to remove a directory from the path.

  5. Invalid paths can be specified without causing errors. Thus a PATH statement can include reference to removable media or network drives. It also means that the only indication of an invalid path caused by a typo or missing semicolon separator (say) is that the program(s) will not be found.

  6. Actually, PATH will accept just about any character without causing an error.

  7. When Windows95/8 loads, the PATH environmental variable is set, by default, to:
    C:\WINDOWS;C:\WINDOWS\COMMAND

  8. The maximum length of the PATH environmental variable is limited only by the available space in the environment - but see "Limitations" below.

Examples:

  1. A typical PATH statement in either Config.sys or Autoexec.bat might be:
    PATH c:\windows;c:\windows\command
    This would enable any executable file in these two directories to be run by simply naming the command/program whatever the current directory might happen to be.

  2. To add the directory c:\downloads to the regular path, enter
    PATH %path%;c:\downloads

  3. To add a directory name that contains a space, enclose the name in inverted commas:
    PATH %path%;c:\"program files"\dos
    or
    PATH %path%;"c:\program files\dos"

Limitations

  1. The maximum length of the Dos command line is restricted to 127 characters.
    The workaround to this is to use the PATH=%path%;additionalpath etc. as shown above.

  2. The maximum length of any single path is limited to 127 characters.
    Although one can construct a longer path, an executable file more than 127 characters from the root directory will not be found either in Dos or Win95. The SUBST statement can be used to make the program visible to Win95, but not Dos.

Further Comments

1. If a path statement contains more than four or five paths, I have found there is much to be said for building up the path using the Path=%path%;addnpath syntax. This makes it easy to see exactly what is on the path and to remove individual paths if no longer required.
For example, in Autoexec.bat one might have:
....
PATH=%path%;c:\dos\batchfiles
PATH=%path%;c:\windows\twain\scanwiz
PATH=%path%;d:\downloads\utilities
....

2. Peter Dolman suggested the following:

To change the path temporarily, and change it back:
Set oldpath=%path%creates an environmental variable called %oldpath%
Set path = newpathwhere newpath is the new path
.......run application, do whatever here
Set path = %oldpath%restores the path to its original configuration
Set oldpath = removes %oldpath% from the environment
.
To add to the path temporarily, and change it back:
Set oldpath=%path%creates an environmental variable called %oldpath%
Set path = %path%; addpathwhere addpath is the additional path(s)
.......run application, do whatever here
Set path = %oldpath%restores the path to its original configuration
Set oldpath = removes %oldpath% from the environment

3. Laurence Soucy suggested this simplified approach which uses no extra environment space:

Save and restore the path
PATH>%temp%.\respath.bat
CALL %temp%.\respath

saves the path into a batch file
restores the path from saved batch file

File Details:

Internal


This page last revised:
December 9, 1999.