1
@echo off
set "RADmainDir=C:\Program Files (x86)\Embarcadero\Studio\20.0\"
set "patchList[0]=bin\dsymlink.exe"
set "patchList[1]=bin\themeloader260.bpl"

set "x=0"
:SymLoop
if defined patchList[%x%] (
    IF EXIST "%RADmainDir%%patchList[%x%]%" (
    echo:OK
    ) ELSE (
    echo:MISSING
    )
    set /a "x+=1"
    GOTO :SymLoop
)

The "if defined" part works. But the "if exist" part doesn't. It seems like that the variable x is a probleme there. How can i solve this problem ?

Output:

"C:\Program Files (x86)\Embarcadero\Studio\20.0\x" MISSING

int3g3r
  • 15
  • 4

1 Answers1

0

You cannot nest variables this way. Try with delayed expansion (not tested):

@echo off
set "RADmainDir=C:\Program Files (x86)\Embarcadero\Studio\20.0\"
set "patchList[0]=bin\dsymlink.exe"
set "patchList[1]=bin\themeloader260.bpl"

setlocal enableDelayedExpansion
set "x=0"
:SymLoop
if defined patchList[%x%] (
    IF EXIST "!RADmainDir!!patchList[%x%]!" (
     echo:OK
    ) ELSE (
     echo:MISSING
    )
    set /a "x+=1"
    GOTO :SymLoop
)

it will be even better and more readable to iterate the array with for loop (also not tested):

@echo off
set "RADmainDir=C:\Program Files (x86)\Embarcadero\Studio\20.0\"
set "patchList[0]=bin\dsymlink.exe"
set "patchList[1]=bin\themeloader260.bpl"

setlocal enableDelayedExpansion

for /l %%l in (0-start;1-step;1-end) do (
  if exist  "!RADmainDir!!patchList[%%l]!" (
     echo exists
  ) else (
     echo does not exists
  )
)

More about the delayed expansion and the for /l loop

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • 1
    I don't want to edit the for loop when i'm adding items to the "patchList", this is why i don't use the for loop statement. But the rest works fine. Thank you! – int3g3r Apr 02 '20 at 11:48
  • @int3g3r - thanks for the update. If this works you can also accept the answer to make it easier for the next users who check this question. – npocmaka Apr 02 '20 at 13:00