1
votes

I'm using a windows command prompt script to read values from different .txt files. First it works, but then later the array seems to be 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
for %%i in %pattern% do (
set j=0
for /f "tokens=1-5" %%a in (.\results\%%i.txt) do (
  if %%a==%comptype% if %%b==Results (set t=%%d)
  if %%a==%ID% (
  set data[%n%][%j%]=%%b
  echo !data[%n%][%j%]!                      <-- This is working
  set /a j=!j!+1 )
)
set /a n=!n!+1
)

for /l %%o in (0, 1, %n%) do (
for /l %%k in (0, 1, %j%) do (
echo %data[%%o][%%k]%                        <-- This is not working
))

The second echo just prints: "ECHO is off.", which leads me to believe that the variable is empty at that point. Could it have something to do with the delayed expansion of 'data'? Using ! instead of % for the second echo does not change anything. EndLocal before or after the last two for-loops also does not help.

1

1 Answers

1
votes

try this:

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