Simulation of a 2-dimensional array with a numerical estimate:
Content textfile.txt :
var 1,val 1 var 2,val 2 var 3,val 3
Contents of test.bat :
@echo off setlocal enabledelayedexpansion set idx=0 for /f "usebackq tokens=1* delims=," %%I in ("textfile.txt") do ( set "var[!idx!][0]=%%~I" set "var[!idx!][1]=%%~J" set /a idx += 1 ) set var
Result:
var[0][0]=var 1 var[0][1]=val 1 var[1][0]=var 2 var[1][1]=val 2 var[2][0]=var 3 var[2][1]=val 3
Or you could model associative arrays whose key-value pair format might make more sense if you are dealing with configuration data.
Associative array modeling:
Content textfile.txt :
key 1=val 1 key 2=val 2 key 3=val 3
Contents of test.bat :
@echo off setlocal for /f "usebackq tokens=1* delims==" %%I in ("textfile.txt") do ( set "config[%%~I]=%%~J" ) set config
Result:
config[key 1]=val 1 config[key 2]=val 2 config[key 3]=val 3
rojo May 22 '15 at 19:02 2015-05-22 19:02
source share