Batch populating array in loop
arraylist, arrays, batch-file, loops
Solution
@echo off
setlocal EnableDelayedExpansion
rem Populate the array with existent files in folder
set i=0
for %%a in (*.*) do (
set /A i+=1
set list[!i!]=%%a
)
set Filesx=%i%
rem Display array elements
for /L %%i in (1,1,%Filesx%) do echo file number %%i: "!list[%%i]!"
You must note that, for convenience, subscripts in Batch arrays should start at 1, not 0.
For further description on array management in Batch files, see: Arrays, linked lists and other data structures in cmd.exe (batch) script
Problem
hi i have a big problem in batch, its kind of complicated to tell, but i figured out the way to solve it, the problem is i didnt know how to do it in batch, if in c# i can do it easily since im new in batch, below is c# , can u guys teach me how to do exactly like that in batch? i google'd whole day but cannot find a way, thanks in advance ``` ArrayList list = new ArrayList(); //let say variable "Filesx" consist of files count in one folder for(int i = 0; i < Filesx; i++){ list.Add("file number : " + i); } ``` P/S: if arraylist is not possible in batch, array alone is ok