%path% in Autoexec.bat?

Status
Not open for further replies.

MooseAreFun

Ars Legatus Legionis
10,827
Subscriptor
When you run a program, say "chicken.exe", the Operating System looks in the current directory for the program.

If you are in "c:\stuff\", it will try to run "c:\stuff\chicken.exe".

This is fine for most programs, but there are a few programs that you want to use from anywhere, like format, ping, etc.

PATH is the solution. Wherever you are, if you try to run a program like "chicken.exe", the OS will look in the current directory, then if the program isn't there it will look through all the directories in the %PATH% environment variable, so you can keep all system files in c:\windows\command and they work from anywhere.

So don't delete the PATH line, but you can delete repeated entries in it.
 

dockeen

Ars Tribunus Militum
1,600
I came across this in a DOS 7 reference, and proceeded to hit myself on the head (wonder why I have memory loss?)

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.

Hope I am answering your question...

Wayne
 

edgevb

Smack-Fu Master, in training
80
%path% is a a way to express the PATH enviornment variable in batch files. It will insert the current contents of the PATH

i.e.
PATH=c:\windows\command;c:\windows\system
.
.
.
PATH=c:\newdirectory\hi;%path%

The PATH will then be
c:\newdirectory\hi;c:\windows\command;c:\windows\system

PATH uses semicolons to delimit directoy paths, and it's usually a good idea to convert any pathnames to the 8.3 naming standard -- meaning long pathnames should be truncated to ABCDEF~X.
 

MrMills

Ars Praefectus
3,727
Moderator
PATH=C:\WINDOWS;C:WINDOWS\COMMAND;C:\PERL\BIN\C:\WINDOWS;C:\WINDOWS\COMMAND

==

PATH=C:\WINDOWS;C:WINDOWS\COMMAND;C:\PERL\BIN

Well, sort of, because the second one works, and the first one would muck up on anything in C:\PERL\BIN. (Look closely if you don't get why. OK, notice that all paths need to be separated by semicolons. That's enough hints.)

Remember, PATH is an environment variable.

To set the path:
PATH C:\WINDOWS;C:WINDOWS\COMMAND;C:\PERL\BIN
or
SET PATH=C:\WINDOWS;C:WINDOWS\COMMAND;C:\PERL\BIN

To append a directory to the path:
SET PATH=%PATH%;C:\DOS\RUN

To prepend a directory to the path:
SET PATH=C:\JANE\HIT\JACK;%PATH%

The following is NOT good:
SET PATH = %PATH%;C:\JACK\BLEED

Spacing *is* important. Capitalization isn't.
 
Status
Not open for further replies.