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), 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...]]

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

Notes:

  1. When Dos searches for a file, it first looks in the current directory, and then the directories listed in the PATH statement 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" 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. A semicolon is not required at the end of the statement.

  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.

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

Examples:

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.

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

Tricks

In response to a newsgroup query in microsoft.public.win95.msdosapps, 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

File Details:

Internal


If you should have any comments or suggestions,
please contact: Bob Watson
.
This page last revised:
December 9, 1999.