Blowfelt82
asked on
Add to PATH environment variable if value does not already exist
I am using the following to add to my PATH environment variable in DOS
Path=%Path%;C:\Windows\Mic rosoft.NET \Framework \v3.5
This works as expected, but the batch file will be run repeatedly so I want to add some code that will only append to the batch file if the value is not actually there? Is this possible?
Also, when I use the SET command in DOS the changes I have made to the environment variable are shown, but when I try and access the information via My Computer > Environment Variables it doesn't look like these have been refreshed? Is there a command I can use to refresh these?
Path=%Path%;C:\Windows\Mic
This works as expected, but the batch file will be run repeatedly so I want to add some code that will only append to the batch file if the value is not actually there? Is this possible?
Also, when I use the SET command in DOS the changes I have made to the environment variable are shown, but when I try and access the information via My Computer > Environment Variables it doesn't look like these have been refreshed? Is there a command I can use to refresh these?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The proper way to do it is with the following command:
if not defined AddPath setx AddPath C:\Windows\Microsoft.NET\Framework\v3.5 /m
After issuing this command, open another DOS box and you will see the variable is set using the SET command.
Also of course keep in mind that the PATH command is a bit odd, and there are other uncommon situations that can occur. For example the paths can be relative in the PATH variable. And it will work with paths using either \ or / between folder names. Paths can be added with a training \ or not. And Paths can be added with quotes around them. So lots of odd cases, but typically we just check for the normal stuff.
Open in new window
Open in new window
~bp