Arrays can be emulated in the delayed expansion mode using the combination of
! to indicate variables. There,
%i% is the value of variable
i with the immediate expansion while
!i! is the value of variable
i in the delayed expansion.
@echo off setlocal EnableDelayedExpansion for /l %%i in (1, 1, 10) do ( set array_%%i=!random! ) for /l %%i in (1, 1, 10) do ( echo !array_%%i! ) :: For each item in the array, not knowing the length set i=1 :startloop if not defined array_%i% goto endloop set array_%i%=!array_%i%!_dummy_suffix echo A%i%: !array_%i%! set /a i+=1 goto startloop :endloop
- Arrays, linked lists and other data structures in cmd.exe (batch) script, stackoverflow.com
Found a mistake? Have a question or improvement idea? Let me know.
Table Of Contents