I\'ve seen SETLOCAL ENABLEDELAYEDEXPANSION
& SETLOCAL DISABLEDELAYEDEXPANSION
in many batch files but what do the commands actually do?
With delayed expansion you will able to access a command argument using FOR command tokens:
setlocal enableDelayedExpansion
set /a counter=0
for /l %%x in (1, 1, 9) do (
set /a counter=!counter!+1
call echo %%!counter!
)
endlocal
Can be useful if you are going to parse the arguments with for loops
It helps when accessing variable through variable:
@Echo Off
Setlocal EnableDelayedExpansion
Set _server=frodo
Set _var=_server
Set _result=!%_var%!
Echo %_result%
And can be used when checking if a variable with special symbols is defined:
setlocal enableDelayedExpansion
set "dv==::"
if defined !dv! (
echo has NOT admin permissions
) else (
echo has admin permissions
)