Windows批处理中的变量变量名称

时间:2014-09-11 12:25:13

标签: windows batch-file

这里有关于Windows批处理文件中变量内部变量的很多主题,我试图理解它们。所以我最终得到了这段代码,但看起来它处于无限循环中:

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
  )
)

结果应该是以下变量:

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

我做错了什么,或者,甚至可能?

2 个答案:

答案 0 :(得分:1)

这是你期望的那种吗?

@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

答案 1 :(得分: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