I will need some help to understand a strange behaviour I want to loop through a directory to find which sub-directories are ending with some specific characters. I wrote this to test:
@ECHO.
setlocal EnableDelayedExpansion
set Dir=C:\test
for /f "tokens=*" %%I in ('dir %Dir% /ad /b') do (
set V1=%%I
set V2=!V1!
set V3=%V1%
set V4=%V1:~-4%
set V5=!V1:~-4!
)
endlocal
The result is:
C:>test
C:>setlocal EnableDelayedExpansion
C:>set Dir=C:\test
C:>for /F "tokens=*" %I in ('dir C:\test /ad /b') do (
set V1=%I
set V2=!V1!
set V3=
set V4=~-4
set V5=!V1:~-4!
)
C:>(
set V1=dir1_011
set V2=!V1!
set V3=
set V4=~-4
set V5=!V1:~-4!
)
C:>(
set V1=dir1_011 - Copie
set V2=!V1!
set V3=
set V4=~-4
set V5=!V1:~-4!
)
C:>(
set V1=dir1_011 - Copie (2)
set V2=!V1!
set V3=
set V4=~-4
set V5=!V1:~-4!
)
C:>(
set V1=dir1_011 - Copie (3)
set V2=!V1!
set V3=
set V4=~-4
set V5=!V1:~-4!
)
C:>(
set V1=dir1_011 - Copie (4)
set V2=!V1!
set V3=
set V4=~-4
set V5=!V1:~-4!
)
C:>(
set V1=dir1_011 - Copie (5)
set V2=!V1!
set V3=
set V4=~-4
set V5=!V1:~-4!
)
C:>(
set V1=dir1_011 - Copie (6)
set V2=!V1!
set V3=
set V4=~-4
set V5=!V1:~-4!
)
C:>(
set V1=dir1_011 - Copie (7)
set V2=!V1!
set V3=
set V4=~-4
set V5=!V1:~-4!
)
C:>(
set V1=dir1_011 - xxx
set V2=!V1!
set V3=
set V4=~-4
set V5=!V1:~-4!
)
C:>endlocal
C:>
I could never get the end of the directory name even if i'm using EnableDelayedExpansion
May be someone has some explanation ?