Over time, many programs may add directories to your PATH environment variable.
The following small batch file checks each entry in the PATH variable and displays if the directory exists or not.
The following code is based on this StackOverflow code.
Put the following code into a text file, e.g. C:\validatepath.bat:
@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
When run, it should output something like:
OK: C:\Users\abcde NOK: C:\this\is\no\dir
Bonus
To just show the directories which don't exist, run this:
validatepath | findstr /b /r /c:"^ *NOK: *.*"

Comments
No comments