I have a file called “VAR.bat” that sets variables:
SET VARa=C:\Program Files
SET VARb=C:\Program Files (x86)
set VARc=C:\ProgramData
I have a file another called “SET.set” that contains just variable names:
VARa
VARb
VARc
I would like to call upon the set from a routine like this:
for /f "tokens=* delims= " %%a in ('type "SET.set"') do (
SET CONSA=%%~a
SET CONSN=%%^%%a%%
CALL :CREATEVAR
)
:CREATEVAR
if exist "%CONSN%" CALL :%CONSA%_detect
exit /b
:VARa_detect
echo "%CONSN%"
exit /b
:VARb_detect
echo "%CONSN%"
exit /b
:VARc_detect
echo "%CONSN%"
exit /b
Using the ^ to escape and add a % to a value isn’t working because the command processor interprets the value as “%VARa%” and not “C:\Program Files“
You could use the delayed expansion here.
Or at the same line you could use an extra expaqnsion by
CALL