Related:
How to list the elements of the path in a batch file?
How does FOR work?
How would you write a batch file or CMD file to remove an element from the path? It should handle gracefully:
- differences in case
- shortnames and long names
I've done this using tr.exe but it's slow and complicated and uses temporary files, which makes it even more complicated.
I think the answer is 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 remove. KeepIfUnique would have to be a subroutine that takes two arguments - directory names, normalizes them, and appends the first argument to tpath if it is not equal to the 2nd argument (elementToRemove).
As I said, I can do this with tr.exe, but can I do it with just built-in commands in the windows cmd.exe shell?
EDIT: I guess when you get right down to it, the question is, how to do case-conversion in cmd.exe?