Arrays
suggest changeArrays can be emulated when delayed expansion is enabled. %name% is the value of environment variable name at parse time, while !name! is the value at execution time. A for variable is still %%i in a batch (%i at the prompt), not %i%.
@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
Links:
- 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