I have an existing windows batch script (named as test1.bat) as below :
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set nop=4
for /l %%z in (1, 1, %nop%) do (
set x=%%z
echo !x!
)
chdir /d D:\app\
Strangely for some reason , the chdir
command at the end does not change the directory to D:\app\
. It does not even throw an error and the script just completes. But when i remove SETLOCAL ENABLEDELAYEDEXPANSION
then the chdir
command works fine.
I want to know why chdir
command is not working when i use SETLOCAL ENABLEDELAYEDEXPANSION
?
Here is the complete code with output
When test1.bat is with SETLOCAL ENABLEDELAYEDEXPANSION
C:\tmp>@test1.bat
1
2
3
4
C:\tmp>
When test1.bat is without SETLOCAL ENABLEDELAYEDEXPANSION
C:\tmp>@test1.bat
!x!
!x!
!x!
!x!
D:\app>