Question: What is simple, reliable way to add a folder to the system path in a batch script only once no matter how many times I run the script?
I need to add a folder to the path permanently. But I only want to add it one time, even if I run the script many times.
Attempts: I am comfortable adding the folder to the path in the environment and the registry:
SETX /m PATH "%PATH%;%MyFolder%"
SET PATH=PATH;%MyFolder%
Yet I need to guarantee it will not keep adding the same folder to the path variable every time it runs. My first thought is to compare strings to check if it already contains the folder, but I need help with the syntax:
REM If the PATH folder does not contain the folder already
IF NOT %MyFolder%==%PATH% (
REM Add the folder to the path
)
Or is there a better way?