double substitutions of variable

February 10, 2010 at 08:08:53
Specs: Windows XP
Hi all,this is my problem:
10 variables
set file1=aaa
set file2=bbbb
set file3=...
etc..

set counter=0
set numFile=10
:LoopStart
if %counter%==%numFile% GOTO LoopEnd
set nameFile= file%counter%
set nameFile=%nameFile%
....
....
set /a counter+=1
GOTO LoopStart
:LoopEnd

I need that after the substitution the content of nameFile is aaa (at the first loop,and so long for the others) but in that way it doesn't work.I'm sure it's wrong but I have no idea about how to do a double substitution..
Another thing I've tried was
set %nameFile%=%%file%counter%%
but the result was the same...
Please help me and thank's!!


See More: double substitutions of variable

Report •


#1
February 10, 2010 at 13:10:36
one method:
setlocal enabledelayedexpansion
...
for /L %%a in (1 1 %numfile%) do (
set namefile=file%%a
echo !namefile!
)

another method (back to your code):
setlocal enabledelayedexpansion
...
:loopstart
set /a counter+=1
set namefile=file!counter!
echo !namefile!
...
goto :loopstart


Report •

#2
February 11, 2010 at 01:24:08
nbrane, try to review the original post as I think he wants the following

setlocal EnableDelayedExpansion
...
for /L %%a in (1 1 %numfile%) do (
  set nameFile=!file%%a!
  echo.!nameFile!
)

or as alternate method

setlocal EnableDelayedExpansion
...
set counter=0
:loop
set /a counter+=1
set nameFile=!file%counter%!
echo.%nameFile%
...
if %counter% lss %numfile% goto :loop


Report •

#3
February 11, 2010 at 08:26:21
yes, I left out one layer from the concept.
those doubles always get me unless I test them.
thanks!

Report •

Related Solutions

#4
February 11, 2010 at 08:37:19
thank's for all this is very helpful
just a question:
for /L %%a in (1 1 %numfile%) do

What is the meaning of /L ?
And the meaning of the condition?


Report •

#5
February 11, 2010 at 08:45:58
http://judago.webs.com/forloopmadne...

I'm not so sure how good my explanations are....


Report •

#6
February 12, 2010 at 03:08:53
Well, pretty good ... the help-pages are not always sufficient, but this is a good help, Judago

It's indeed easier if you name the kind of loop (FOR /F, FOR /L, ... etc) then you remember them that way


Report •


Ask Question