for loop - Windows batch: data from file disappears after delayed expansion -


i'm using windows command prompt script read values different .txt files. first works, later array seems empty.

analyze.bat:

@echo off setlocal enabledelayedexpansion set id=p8 set comptype=link set pattern=(700 710 720 730 740 750 760 770 780 790 )   set n=0 %%i in %pattern% ( set j=0 /f "tokens=1-5" %%a in (.\results\%%i.txt) (   if %%a==%comptype% if %%b==results (set t=%%d)   if %%a==%id% (   set data[%n%][%j%]=%%b   echo !data[%n%][%j%]!                      <-- working   set /a j=!j!+1 ) ) set /a n=!n!+1 )  /l %%o in (0, 1, %n%) ( /l %%k in (0, 1, %j%) ( echo %data[%%o][%%k]%                        <-- not working )) 

the second echo prints: "echo off.", leads me believe variable empty @ point. have delayed expansion of 'data'? using ! instead of % second echo not change anything. endlocal before or after last 2 for-loops not help.

try this:

set "data[!n!][!j!]=%%b" ... ... echo !data[%%o][%%k]! 

Comments