In the case of a risk associated with a decrease, until the expert provides a reliable way to do this,
below deletes a specific path from the environment variable, if one exists, so that it can be added again:
set str=%path% :: str is the same with path set str=%str:;C:\Path\To\Add=% :: ";c:\path\to\add" is now removed from str setx Path "%str%;c:\path\to\add" -m :: proceed with setting the path
This carries the risk of deleting the line if it is actually part of the path, for example c:\path\to\add\somefolder . Also, if the path actually ends with \ , or this is the first record, and it does not actually start with ; etc.
Different forms can be called sequentially to get around some of them,
set str=%str:;C:\Path\To\Add\;=;% set str=%str:;C:\Path\To\Add;=;% set str=%str:;C:\Path\To\Add\=% set str=%str:C:\Path\To\Add\;=% set str=%str:;C:\Path\To\Add=%
But, AAMOF I'm not sure if this is a reasonable way to do this.
source share