I'm trying to check if files from an array exists. The array and the loop are working fine, but the if exists
-line gives a syntaxerror. I tried different variations (%%list[%x%]%%
, list[%x%]
, %%list[%%x%%]%%
), but none of them works.
Question: Why is the if exists %%list[%x%]%%
not working, but the call echo Check file: %%list[%x%]%%
works?
Hint: I use this kind of "loop", because I want that the coded hasn't to be changed if the size of the array changes.
set list[0]="C:\file_a.txt"
set list[1]="C:\file_b.txt"
set list[2]="C:\file_c.txt"
set "found=0"
set "notfound=0"
set "x=0"
:SymLoop
if defined list[%x%] (
call echo Check file: %%list[%x%]%%
if exists %%list[%x%]%% (
set /a "found+=1"
) else (
set /a "notfound+=1"
)
set /a "x+=1"
GOTO :SymLoop
)
echo %found%/%x% file found. %notfound% files missing!
PAUSE
Solved: The problem was the missing "Delayed Expansion" and in addition a typo (exists instead of exist).