I want to set PATH
for a tool I wrote using a batch file. But I only want to modify it if the path I want to add isn't already contained in that String
. I think I get the syntax wrong because I can't get it to work.
@setlocal enableextensions enabledelayedexpansion
@echo off
set MinGWmsys="%CD%\tools\MinGW\msys\1.0\bin;"
set MinGWbin="%CD%\tools\MinGW\bin;"
set SDCCbin="%CD%"\tools\SDCC\bin;"
set lpath="%PATH%"
if not x%lpath:%MinGWmsys%=% == x%lpath% (
echo PATH already contained %MinGWmsys%
) else (
echo Adding %MinGWmsys% to PATH
setx PATH "%MinGWmsys%;%PATH%"
)
if not x%lpath:%MinGWbin%=% == x%lpath% (
echo PATH already contained %MinGWbin%
) else (
echo Adding %MinGWbin% to PATH
setx PATH "%MinGWbin%;%PATH%"
)
if not x%lpath:%SDCCbin%=% == x%lpath% (
echo PATH already contained %SDCCbin%
) else (
echo Adding %SDCCbin% to PATH
setx PATH "%SDCCbin%;%PATH%"
)
endlocal
Can somebody help me here please?