How-to Clean Up Your %PATH%
As developers, we frequently end up with duplicate entries in our path. From the command line you can clean up your path using pathman.exe. Here’s a PowerShell Script to find the duplicates and remove them using Pathman.exe:
$extraPath=(($env:path.Split(';') | group | ?{$_.Count -gt 1}).Values | %{$_[0]} pathman.exe /ru $extrapath
Disclaimer: Works for us.
Hi, looks likes there’s a bug!
I improved upon the idea a bit and published this Gist:
https://gist.github.com/asheroto/fa216475272e58837b06c4be61088530
Here is a “cute” way to do it in plain CMD shell script:
I called the script “CleanupPath.cmd” and you just run it and your path duplicates will be removed without changing the order of the path.
@setlocal EnableExtensions EnableDelayedExpansion
@set _PATH_=
@for %%a in (“%PATH:;=” “%”) do @if not “%%~a” == “” (
@if “!_PATH_!” == “” @set “_PATH_=;%%~a;”
@set “_T_=!_PATH_:;%%~a;=x!”
@if “!_T_!” == “!_PATH_!” @set “_PATH_=!_PATH_!%%~a;”
)
@endlocal && @set “PATH=%_PATH_:~1,-1%
!!!! Thank you! I changed the right-double-quotes and left-double-quotes to just plain double-quotes and this worked on the first try!!!
Wow… impressive!
Can’t work. At least one closing “)” is missing.