To create an array:
setlocal EnableDelayedExpansion set i=0 for /F %%a in (theFile.txt) do ( set /A i+=1 set array[!i!]=%%a ) set n=%i%
To print array elements:
for /L %%i in (1,1,%n%) do echo !array[%%i]!
If you want to pass the array name and length as parameters of the subroutine, use the following method:
call theSub array %n% :theSub arrayName arrayLen for /L %%i in (1,1,%2) do echo !%1[%%i]! exit /B
source share