1

我想要 2 种类型的列表第一个列表的类型,例如每天和发布,第二个类型的第一个列表的路径。之后,我想根据第一个类型列表动态地浏览第二个类型列表。

像这样的东西:

@ECHO OFF

REM ##########
REM ## Test ##
REM ##########

SETLOCAL EnableDelayedExpansion

SET VersionType=(Daily Release)
SET TagetsDaily=(path1 path2)
SET TagetsRelease=(path23 path24)


FOR %%n IN %VersionType% DO (
    ECHO !Tagets%%n!
    SET test_temp=!Tagets%%n!
    ECHO %test_temp%

    FOR %%i !Tagets%%n! DO (
        ECHO %%i
    )
)

PAUSE
EXIT

这段代码的问题是它不起作用。

输出:

"!Tagets%n!" can be syntactically processed at this point.

并且没有第二个:

(path1 path2)
ECHO is off (OFF).
(path23 path24)
ECHO is off (OFF).

谁能解释一下为什么这是一个语法错误以及为什么我可以从 !Tagets%%n 复制内容!进入另一个变量??

4

1 回答 1

2

尝试这个:

@ECHO OFF &SETLOCAL ENABLEDELAYEDEXPANSION
SET "VersionType=Daily Release"
SET "TagetsDaily=path1 path2"
SET "TagetsRelease=path23 path24"

FOR %%n IN (%VersionType%) DO (
     ECHO !Tagets%%n!
     SET test_temp=!Tagets%%n!
     ECHO !test_temp!

     FOR %%i IN (!Tagets%%n!) DO (
          ECHO %%i
     )
)

请看for /?delayed expansion

于 2013-07-18T16:33:44.097 回答