Page 1 of 1

Does "endlocal" close all instances of "setlocal"?

Posted: 23 Jul 2023 07:54
by PiotrMP006
Does "endlocal" close all instances of "setlocal"?

ex

Code: Select all

setlocal enabledelayedexpansion enableextensions
set name1=1

setlocal disabledelayedexpansion enableextensions
set name2=2

setlocal enabledelayedexpansion enableextensions
set name3=3

endlocal

Re: Does "endlocal" close all instances of "setlocal"?

Posted: 23 Jul 2023 08:33
by OJBakker
Just add a few lines to your script and the answer is obvious.
Try the script below.

Code: Select all

setlocal enabledelayedexpansion enableextensions
set name1=1
setlocal disabledelayedexpansion enableextensions
set name2=2
setlocal enabledelayedexpansion enableextensions
set name3=3
set name
endlocal
set name
endlocal
set name

Re: Does "endlocal" close all instances of "setlocal"?

Posted: 20 Aug 2023 21:36
by shodan
To anyone curious but don't feel like testing, here is the answer

Code: Select all

D:\dev\work>endlocal-depth-tester.bat
D:\dev\work>setlocal enabledelayedexpansion enableextensions
D:\dev\work>set name1=1
D:\dev\work>setlocal disabledelayedexpansion enableextensions
D:\dev\work>set name2=2
D:\dev\work>setlocal enabledelayedexpansion enableextensions
D:\dev\work>set name3=3
D:\dev\work>set name
name1=1
name2=2
name3=3
D:\dev\work>endlocal
D:\dev\work>set name
name1=1
name2=2
D:\dev\work>endlocal
D:\dev\work>set name
name1=1