There is a useful script called paths.bat in my System Tools Library that can help you do that:
https://github.com/JFLarvoire/SysToolsL ... sTools.zip
When invoked without any option, the paths.bat script displays the current PATH with 1 pathname per line.
This makes it considerably easier to see what your PATH contains, particularly when it is very long. (Mine has 53 entries!)
You can also filter the output with find or findstr, to look for a needle in the haystack. Ex:
Code: Select all
C:\JFL\Temp>echo %PATH%
C:\Program Files (x86)\VMware\VMware Player\bin\;C:\Program Files\Eclipse Adoptium\jdk-8.0.345.1-hotspot\bin;C:\Program Files\Amazon Corretto\jdk11.0.16_8\bin;C:\ProgramData\chocolatey\bin;C:\JFL\Tools;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Tcl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\JFL\Tools\Win64;C:\JFL\Tools\Win32;C:\JFL\Tools\ezWinPorts\Win64\bin;C:\JFL\Tools\ezWinPorts\Win32\bin;C:\JFL\Tools\UnxUtils\usr\local\wbin;C:\JFL\Tools\GnuWin32\bin;C:\JFL\Tools\SysInternals;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\dotnet\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\jEdit;C:\JFL\SDK\git-subrepo\lib;C:\Program Files\Python39;C:\Program Files\Python39\scripts;C:\Program Files\TortoiseGit\bin;C:\PROGRA~2\GTK\bin;C:\Program Files\Pandoc;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Calibre2\;C:\Program Files\Git\cmd;C:\Program Files\Pandoc\;C:\Program Files\GitHub CLI\;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\CMake\bin;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\nodejs\;C:\Program Files (x86)\gsudo\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\PowerShell\7\;C:\Users\Larvoire\scoop\shims;C:\Users\Larvoire\AppData\Local\atom\bin;C:\Users\Larvoire\AppData\Local\Microsoft\WindowsApps;C:\Users\Larvoire\.dotnet\tools;C:\Users\Larvoire\AppData\Local\Markdown Monster;C:\Users\Larvoire\.dotnet\tools;C:\Users\Larvoire\AppData\Local\Yarn\bin;C:\Users\Larvoire\AppData\Roaming\npm
C:\JFL\Temp>paths
C:\Program Files (x86)\VMware\VMware Player\bin\
C:\Program Files\Eclipse Adoptium\jdk-8.0.345.1-hotspot\bin
C:\Program Files\Amazon Corretto\jdk11.0.16_8\bin
[...]
C:\Users\Larvoire\.dotnet\tools
C:\Users\Larvoire\AppData\Local\Yarn\bin
C:\Users\Larvoire\AppData\Roaming\npm
C:\JFL\Temp>paths | findstr /i tools
C:\JFL\Tools
C:\JFL\Tools\Win64
C:\JFL\Tools\Win32
C:\JFL\Tools\ezWinPorts\Win64\bin
C:\JFL\Tools\ezWinPorts\Win32\bin
C:\JFL\Tools\UnxUtils\usr\local\wbin
C:\JFL\Tools\GnuWin32\bin
C:\JFL\Tools\SysInternals
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\
C:\Users\Larvoire\.dotnet\tools
C:\Users\Larvoire\.dotnet\tools
C:\JFL\Temp>
By default, paths.bat manages the PATH variable.
But it can be used with any other variable containing a list of strings separared by semi-colons. For example the PATHEXT, INCLUDE, or LIB variables. Ex:
Code: Select all
C:\JFL\Temp>paths PATHEXT
.COM
.EXE
.BAT
.CMD
.PY
[...]
By default, it manages the local environment variable.
But this can be changed to the system or user variables in the registry, by using the -s and -u options respectively.
And finally, to answer your initial request, paths.bat has options for adding, changing, or removing individual paths in the PATH. (Or in any other similar variable.)
There are also several options for choosing where the new path goes. (Ahead, in the end, or before a given entry.)
Use option -? for displaying a help screen with all options.
For your request, the command to remove the current directory from the system PATH would be something like:
For adding the current directory, it'd be:
Note that the -a command only adds a path if it's not already there, so you don't have to check that yourself.
Note also that, if you want to know what paths.bat is doing under the hood, you can do a dry-run using the -X (no-execute) option. That will display the command(s) generated that would do the job. Ex:
Code: Select all
C:\JFL\Temp>paths -X -s -r "C:\Program Files (x86)\VMware\VMware Player\bin\"
reg add "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /f /v PATH /d "C:\Program Files\Eclipse Adoptium\jdk-8.0.345.1-hotspot\bin;C:\Program Files\Amazon Corretto\jdk11.0.16_8\bin;C:\ProgramData\chocolatey\bin;C:\JFL\Tools;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Tcl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\JFL\Tools\Win64;C:\JFL\Tools\Win32;C:\JFL\Tools\ezWinPorts\Win64\bin;C:\JFL\Tools\ezWinPorts\Win32\bin;C:\JFL\Tools\UnxUtils\usr\local\wbin;C:\JFL\Tools\GnuWin32\bin;C:\JFL\Tools\SysInternals;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\dotnet\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\jEdit;C:\JFL\SDK\git-subrepo\lib;C:\Program Files\Python39;C:\Program Files\Python39\scripts;C:\Program Files\TortoiseGit\bin;C:\PROGRA~2\GTK\bin;C:\Program Files\Pandoc;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Calibre2\;C:\Program Files\Git\cmd;C:\Program Files\Pandoc\;C:\Program Files\GitHub CLI\;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\CMake\bin;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\nodejs\;C:\Program Files (x86)\gsudo\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\PowerShell\7\\"
setx PROCESSOR_ARCHITECTURE -k "HKLM\System\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE" -m &:# Broadcast a WM_SETTINGCHANGE message