I am writing an batch file in Windows to run post-installation scripts, and one of the things that needs to be done is to add a directory to the system path.
The script is working, and it does something like this:
setx Path "%PATH%;c:\path\to\add" -m
This is setting the path correctly, but this script could potentially be run multiple times if the user reinstalls the program.
I would like to search the string for c:\path\to\add so I don’t keep adding the same path over and over to the system path. This is pretty trivial in Linux with sed, but I don’t know what the command is in Windows. I’ve found findstr, but this seems to only work on files.
Is this possible in Windows without installing additional software?
EDIT:
I’m using Inno Setup to create the install executable.
At the risk of some downvotes till an expert provides a sound way of doing this,
the below removes the specific path from the environment variable if it exists, so that it can be added again:
This carries the risk of removing the string if it is in fact actually a part of a path, for instance
c:\path\to\add\somefolder. Also if the path actually ends with a\, or it is the first entry and it in fact does not start with;, etc..Various forms can be called consecutively to circumvent some of these,
But, AAMOF I’n not sure this is a sane way of doing this..