Related:
How to list path elements in a batch file?
How does FOR work?
How would you write a batch file or CMD file to remove an element from a path? It should handle gracefully:
- differences in case
- short names and long names
I did this with tr.exe, but it is slow and complex and uses temporary files, which makes it even more complex.
I think the answer looks something like this:
setlocal
set tpath=""
set _path="%PATH:;=" "%"
for %%p in (%_path%) do (
call :KeepIfNotEqual %%p %elementToRemove%
)
endlocal & set path=%tpath%
... where% elementToRemove% is the path element to delete. KeepIfUnique should be a routine that takes two arguments - directory names, normalizes them and adds the first argument to tpath if it is not equal to the second argument (elementToRemove).
, tr.exe, windows cmd.exe?
: , , , case- cmd.exe?