I\'ve seen SETLOCAL ENABLEDELAYEDEXPANSION
& SETLOCAL DISABLEDELAYEDEXPANSION
in many batch files but what do the commands actually do?
Copied from How do you use SETLOCAL in a batch file? (as dbenham indicated in his first comment).
Suppose this code:
If "%getOption%" equ "yes" (
set /P option=Enter option:
echo Option read: %option%
)
Previous code will NOT work becase %option% value is replaced just one time when the IF command is parsed (before it is executed). You need to "delay" variable value expansion until SET /P command had modified variable value:
setlocal EnableDelayedExpansion
If "%getOption%" equ "yes" (
set /P option=Enter option:
echo Option read: !option!
)
Check this:
set var=Before
set var=After & echo Normal: %var% Delayed: !var!
The output is: Normal: Before Delayed: After