0

I'm trying to do some scripting and I'm stack with this.

I have a file called "songs.txt" that it has 14 lines with some text. I'm filtering each line by some criteria and put every line filtered inside an array.

The problem is when I try to iterate a value of an array inside the for loop. This is my code:

setlocal EnableDelayedExpansion

set i=1

for /F %%a in (songs.txt) do (
  set elem[!i!]=%%a
  set /A i+=1
)

set x=1

:: nsongs is the length of the lines inside of hte file songs.txt
for /L %%b in (1,1,%nsongs%) do (
  echo START Track %%b: !elem[%%b]!

  :: Now, the problem, this echo END Track... is not showing the array value at position %x%
  echo END Track %%b: !elem[%x%]!
  set /A x+=1
  echo --------------------------
)

endlocal

Any thoughts?

Thank you.

  • Ok fixed, thanks! The problem was the "echo" statement, it should be "call echo" so the solutions is: call echo END Track %%b: !elem[%x%]! – user4665278 Mar 18 '20 at 21:25
  • Well, it should actually read `call echo END Track %%b: %%elem[!x!]%%`... – aschipfl Mar 19 '20 at 00:22

0 Answers0