-1

So I am going crazy. I'm fairly good with most languages but batch programming makes me crazy.

All i want to do is:

  1. Create a loop that reads file (line by line)
  2. Each loop read each line into an array
  3. Each loop read each array value into a separate variable
  4. Use that variable, let's say echo that variable

Anyone?

  • 1
    What's wrong with using any of the [multiple duplicate questions](http://stackoverflow.com/search?q=%5Bbatch-file%5D+read+file+array)? – wOxxOm Sep 18 '15 at 16:54

1 Answers1

1
@echo off

rem Next command is required to easily manage array elements
setlocal EnableDelayedExpansion

rem Create a loop that reads file (line by line)
set numLines=0
for /F "delims=" %%a in (file.txt) do (
   rem Each loop read each line into an array
   set /A numLines+=1
   set "line[!numLines!]=%%a"
)

rem Use that variable, let's say echo that variable
for /L %%i in (1,1,%numLines%) do echo !line[%%i]!

I suggest you to read: Arrays, linked lists and other data structures in cmd.exe (batch) script

Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108