for 循环...在 for 循环中...在 for 循环中?

for 循环...在 for 循环中...在 for 循环中?

因此,我需要在很多位置检查两个可能的文件名,但目录名称却各不相同。

因此,这基本上就是我想要优化的内容:

for /r "%ProgramFiles%\WildGames" %%i in (Uninstall.exe) do ( if exist "%%i" "%%i" /silent ) >nul 2>&1
for /r "%ProgramFiles(x86)%\WildGames" %%i in (Uninstall.exe) do ( if exist "%%i" "%%i" /silent ) >nul 2>&1
for /r "%ProgramFiles%\WildGames" %%i in (Uninstaller.exe) do ( if exist "%%i" "%%i" /silent ) >nul 2>&1
for /r "%ProgramFiles(x86)%\WildGames" %%i in (Uninstaller.exe) do ( if exist "%%i" "%%i" /silent ) >nul 2>&1

但我还需要检查其他位置,而不仅仅是 WildGames。我正在执行以下操作:

set wtlist1[0]=%ProgramFiles%
set wtlist1[1]=%ProgramFiles(x86)%

set wtlist2[0]=Acer Games
set wtlist2[1]=ASUS Games
set wtlist2[2]=Dell Games
set wtlist2[3]=Gateway Games
set wtlist2[4]=HP Games
set wtlist2[5]=Lenovo Games
set wtlist2[6]=TOSHIBA Games
set wtlist2[7]=WildTangent
set wtlist2[8]=WildTangent Games
set wtlist2[9]=WildGames

set wtlist3[0]=Uninstall.exe
set wtlist3[1]=Uninstaller.exe

现在我有点困惑。我知道我必须做点什么 - 就像这样:

for %%a in (wtlist2[0],1,wtlist2[9]) do (
    for %%b in (wtlist1[0],1,wtlist1[1]) do (
        for %%c in (wtlist3[0],1,wtlist3[1]) do (
            echo C:\%%b\%%a\%%c
        )
    )
)

但显然并非完全如此,到目前为止我基本上已经把自己搞糊涂了。我的数组没有增加 1,但除此之外看起来这可能有效?

谢谢!

答案1

@ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
set "wtlist1[0]=%ProgramFiles%"
set "wtlist1[1]=%ProgramFiles(x86)%"

set "wtlist2[0]=Acer Games"
set "wtlist2[1]=ASUS Games"
set "wtlist2[2]=Dell Games"
set "wtlist2[3]=Gateway Games"
set "wtlist2[4]=HP Games"
set "wtlist2[5]=Lenovo Games"
set "wtlist2[6]=TOSHIBA Games"
set "wtlist2[7]=WildTangent"
set "wtlist2[8]=WildTangent Games"
set "wtlist2[9]=WildGames"

set "wtlist3[0]=Uninstall.exe"
set "wtlist3[1]=Uninstaller.exe"

for /L %%a in (0,1,9) do (
    for /L %%b in (0,1,1) do (
        for /L %%c in (0,1,1) do (
            echo "!wtlist1[%%b]!\!wtlist2[%%a]!\!wtlist3[%%c]!"
        )
    )
)

另一种方法:

@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
for %%a in (
    "Acer Games"
    "ASUS Games"
    "Dell Games"
    "Gateway Games"
    "HP Games"
    "Lenovo Games"
    "TOSHIBA Games"
    "WildTangent"
    "WildTangent Games"
    "WildGames"
) do (
    for %%b in (
        "%ProgramFiles%"
        "%ProgramFiles(x86)%"
    ) do (
        for %%c in (
            "Uninstall.exe"
            "Uninstaller.exe"
        ) do (
            echo "%%~b\%%~a\%%~c"
        )
    )
)

资源(必读):

答案2

for %%a in (one two three) do (
    for %%b in (six seven nine) do (
        echo C:\%%a\%%b
    )
)

根据需要重复多次。

相关内容