0

I have encounter a problem in getting array value, the following is my code snippets:

setlocal enabledelayedexpansion
set arraynum=0
set count=0
set list[0]=1
For /R %cd%\ %%G IN (*) do (
set filenum=%%G
echo %%G
set list[!arraynum!]=!filenum!
set /a arraynum+=1
)

echo %arraynum%
echo %list%
echo %count%
echo %%list[%count%]%%
pause

the result value of %%list[%count%]%% is %list[0]%, not the value of filename, it's very strange and is there any way or any instruction to cover that, thanks a lot.

abramhum
  • 443
  • 2
  • 8
  • 20
  • 1
    Does this answer your question? [Arrays, linked lists and other data structures in cmd.exe (batch) script](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script) – T3RR0R Jun 16 '20 at 11:20

1 Answers1

1

Since you already have delayed expansion enabled, you can use it to get the array value.

echo !list[%count%]!

If you didn't have it enabled, you could have used call instead.

call echo %%list[%count%]%%
SomethingDark
  • 13,229
  • 5
  • 50
  • 55