Cuthbeorht
Cuthbeorht

Reputation: 277

How to add a %VAR% to the Windows system PATH within a batch file

I have been searching for a way to add a %var% to the system PATH in Windows 7. I am currently doing the following:

setx PATH "%PATH%;%PATH1%;%PATH2%;" /m

This works as expected. It adds whatever is in those system variables to the Path. However, I want to add the actual string '%PATH1%' to the system Path so if I make changes to the %PATH1% variable, it gets reflected in the PATH.

How do I do this?

EDIT

Currently, in Windows, I have these system variables:

Path1 = c:\path
Path2 = c:\another\path

I am using a batch process to create these system variables. I want to add these new variables to the PATH like this:

PATH = <other paths>;%PATH1%;%PATH2%

Currently, it shows up as:

PATH = <other paths>;c:\path; c:\another\path

My reasoning is that I want to edit the system variable and have the PATH updated at the same time.

Upvotes: 2

Views: 162

Answers (1)

jeb
jeb

Reputation: 82327

You can add %var% literally, but that will not work as you expect.

Then cmd.exe tries to find files in a directory called %var% which normally will not exist on your system. It will not expand %var% inside your path variable.

If you try it (on the console) and a batch exists in C:\temp with the name "myTest.bat"

set path=%path%;%^var%
set path
set var=C:\temp
set path
myTest

The output will be

C:\windows;....;%var%
C:\windows;....;%var%
Can't find internal or external command "mytest"

Upvotes: 2

Related Questions