I am trying to make a batch script that will take the names of all sub-folders in a directory as variables for use elsewhere.
The section of code that is confusing me is:
for /d %%D in (C:\Users\tcsupport\Desktop\Test\*) ^
do (SET test=%%D
echo %%D
echo %test%
echo %test:~32%)
The sub folders in the directory 'Test' are: 1, 2#, 3, ads, and ghf.
These are just random names for testing.
The output I am getting is:
C:\Users\tcsupport\Desktop\Test\1
C:\Users\tcsupport\Desktop\Test\ghf
ghf
C:\Users\tcsupport\Desktop\Test\2#
C:\Users\tcsupport\Desktop\Test\ghf
ghf
C:\Users\tcsupport\Desktop\Test\3
C:\Users\tcsupport\Desktop\Test\ghf
ghf
C:\Users\tcsupport\Desktop\Test\ads
C:\Users\tcsupport\Desktop\Test\ghf
ghf
C:\Users\tcsupport\Desktop\Test\ghf
C:\Users\tcsupport\Desktop\Test\ghf
ghf
but I was expecting:
C:\Users\tcsupport\Desktop\Test\1
C:\Users\tcsupport\Desktop\Test\1
1
C:\Users\tcsupport\Desktop\Test\2#
C:\Users\tcsupport\Desktop\Test\2#
2#
C:\Users\tcsupport\Desktop\Test\3
C:\Users\tcsupport\Desktop\Test\3
3
C:\Users\tcsupport\Desktop\Test\ads
C:\Users\tcsupport\Desktop\Test\ads
ads
C:\Users\tcsupport\Desktop\Test\ghf
C:\Users\tcsupport\Desktop\Test\ghf
ghf
Can anyone explain why this is happening or think of a way around it?