I’ve got a batch file that modifies the PATH variable by prepending a few addresses. When the user logs off-then-on, PATH is reset to its original value (before the batch file was ever run). This behavior is OK.
However, if the batch file is run more than once, the same values are re-prepended and I end up with a overly long, redundant PATH variable that just gets longer after each batch run.
I’d like to reset the variable to whatever it is when the user logs on, before the values are prepended. I figure the solution is to write the original value in a temp file and read it back, but is there a better way to do it?
Rather than writing the original value to a temp file, you could write it to another environment variable:
but it would be better to explicitly check whether the string you want is in PATH already or not, like this: