This does not relate directly to my development project but I am curious none the less. Recently, after a lot of head-banging, I traced a build problem to an invalid entry in the System PATH variable. On my machine, it contains about 20 entries. I am guessing there has to be an easier way to verify the validity of each entry. Can anyone suggest a way to check this? Thanks for your time.
Asked
Active
Viewed 2,764 times
1
-
call me crazy, but in the time it would take to script this you could just plug in the 20 paths to check them. In fact in the time it took to login and type the question you could have checked them all. – CrazyDart Sep 07 '11 at 17:12
-
dup - http://stackoverflow.com/questions/141344/how-to-check-if-directory-exists-in-path – CrazyDart Sep 07 '11 at 17:33
-
valid = ?. Whether it exists? I am wondering if the existence would make a difference to cause a build failure? – Arun Sep 07 '11 at 18:33
1 Answers
8
This code in a batch file (based on this answer) works for me:
@echo off
setlocal DisableDelayedExpansion
set "var=%PATH%"
set "var=%var:"=""%"
set "var=%var:^=^^%"
set "var=%var:&=^&%"
set "var=%var:|=^|%"
set "var=%var:<=^<%"
set "var=%var:>=^>%"
set "var=%var:;=^;^;%"
rem ** This is the key line, the missing quote is intention
set var=%var:""="%
set "var=%var:"=""%"
set "var=%var:;;="";""%"
set "var=%var:^;^;=;%"
set "var=%var:""="%"
set "var=%var:"=""%"
set "var=%var:"";""=";"%"
set "var=%var:"""="%"
setlocal EnableDelayedExpansion
for %%a in ("!var!") do (
endlocal
call :testdir "%%~a"
setlocal EnableDelayedExpansion
)
goto :eof
:testdir
if exist %1 echo OK: %1
if not exist %1 echo NOK: %1
Put the code into a text file, e.g. validatepath.bat
.
When run, it should output something like:
OK: C:\Users\abcde
NOK: C:\this\is\no\dir

Community
- 1
- 1

Joachim Werner
- 166
- 1
- 6