1

There's a lot of topics about variable inside variables in a Windows batch files in here, and I tried to understand them. So I end up with this code, but looks like it's in a infinite loop:

setlocal enabledelayedexpansion

for /l %%a in (RPR SAM) do (
  for /l %%w in (000 iso pic) do (
    set /a a!w!=H:\MyPath\!%%a\!%%a!%%w
  )
)

The result should be the following variables:

RPR000=H:\MyPath\RPR\RPR000
RPRiso=H:\MyPath\RPR\RPRiso
RPRpic=H:\MyPath\RPR\RPRpic

SAM000=H:\MyPath\SAM\SAM000
SAMiso=H:\MyPath\SAM\SAMiso
SAMpic=H:\MyPath\SAM\SAMpic

What am I doing wrong, or, is it even possible?

2 Answers 2

1

Is this the sort of thing you expect?

@echo off
for %%a in (RPR SAM) do (
  for %%w in (000 iso pic) do (
    set zzz%%a%%w=H:\MyPath\%%a\%%a%%w
  )
)
set zzz 
pause
Sign up to request clarification or add additional context in comments.

2 Comments

Almost, the variables are being called zzzRPRiso, zzzRPRpic , zzzRPR000 and so on... I need them to be named without zzz, because they're accessed by a third party application which I can't control. And if I remove the zzz on the loop it does not set any variable at all.
It will create the variables just fine if you remove the zzz in both places - you just won't see them listed as easily.
0
@echo off
set /a a=0
:@
if 1%1==1 (
set Last=%0
GOTO :@@ 
)
set VarB=%VarB% %1
@shift
goto :@
:@@
set /a a=%a%+1
FOR /F "TOKENS=%a%* DELIMS= " %%G IN ('echo %VarB%') do (
FOR /F "TOKENS=1 DELIMS= " %%A IN ('echo %%G') do (

set Var%a%=%%G
set VarA%a%=%%H
set VarR=%%G
)
)
if 1%VarR%==1%Last% goto :A
goto :@@
:A
echo |echo %%Var%a%%%
    REM In Batch Scripts use Double Percent on the outside like dealing with a for statement.
    REM In CMD.exe just use echo [The Character Pipe] echo %Var%a%% 
exit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.