Remove Values from Path

JayGee 181 Reputation points
2021-03-20T20:12:28.067+00:00

What is the correct way to add and remove paths to and from the User PATH environment variable?
I was using emscripten's SDK, which seems to add to the path, this way...
PATH += C:\emsdk
PATH += C:\emsdk\emscripten\1.45.20

I am wondering if I can remove paths using PATH -= E:\myPath.
I have seen other recommendations but I am not sure what's best practice, and guaranteed to be always successful.

I was looking at the setx command here, but I don't understand how I might use it to remove a specific path from the PATH variable. . . if I can.

You can't use this command to remove values added to the local or system environments. You can use this command with a variable name and no value to remove a corresponding value from the local environment.
. . .

Running this command on an existing variable removes any variable references and uses expanded values.
For instance, if the variable %PATH% has a reference to %JAVADIR%, and %PATH% is manipulated using setx, %JAVADIR% is expanded and its value is assigned directly to the target variable %PATH%. This means that future updates to %JAVADIR% will not be reflected in the %PATH% variable.

What is the best way, and or, can I use PATH -= E:\myPath?

PS
I'm sorry if I posted in the wrong forums. Please refer me to the correct Microsoft forums. Thank you.

Sysinternals
Sysinternals
Advanced system utilities to manage, troubleshoot, and diagnose Windows and Linux systems and applications.
1,126 questions
0 comments No comments
{count} votes