3

So I have a bunch of locations I need to check for two possible filenames, however the directory names vary.

So here's essentially what I'm trying to optimize:

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

Except I need to also check for other locations, not just WildGames. I'm doing the following:

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

Now here's where I'm a bit confused. I know I have to do something -LIKE- this:

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

But obviously not exactly that, and I've basically confused myself up to this point. my array isn't incrementing by 1, but otherwise it looks like this might work?

Thanks!

Flux
  • 33
  • 3

2 Answers2

4
@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]!"
        )
    )
)

Another approach:

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

Resources (required reading):

JosefZ
  • 13,217
  • THANKS SO MUCH! This is perfect! I was quite close in what I was trying by the looks of it, but I didn't fully understand it. – Flux Dec 22 '15 at 03:50
  • @JosefZ I've seen a lot of your advanced batch script stuff and upvoted many of then here on SU and on SE so I wanted to be sure you at least saw this to serve it further justice in case you have some input, gotchas, advanced techniques, etc. which may be related. . . http://superuser.com/questions/1106951/batch-script-redirection-syntax. – Vomit IT - Chunky Mess Style Aug 02 '16 at 04:37
1
for %%a in (one two three) do (
    for %%b in (six seven nine) do (
        echo C:\%%a\%%b
    )
)

Repeat as many times as needed.

u1686_grawity
  • 452,512
  • thanks! that does clarify a bit, but not enough unfortunately, I'm quite new to this! – Flux Dec 21 '15 at 06:09
  • to.. the OP, grawity's answer pretty much run the loops as you need then appends them to the c:\ prefix giving you a $PATH of sorts for finding your target locations – linuxdev2013 Dec 21 '15 at 13:11