Here I want to expand a variable inside a variable name and then expand the second variable too.
If it was not a for loop I would have used:-
Code: Select all
setlocal enabledelayedexpansion
Set foo=1
Set bar1=main
Echo !bar%foo%!
This code would echo the content of variable bar1.
But in a for loop:-
Code: Select all
setlocal enabledelayedexpansion
Set var=0
for /f %%a in ('dir /b') do (
Set var+=1
Set file%var%=%%a
Echo !file%var%!
)
This code should set all the file/folder names to different variables and print them but it doesn't because %var% just expands before the command starts executing.
I have found a way to do so by using another 'for /l' loop but that doesn't solves my question, that's just a workaround so, help anyone?