0

I am currently trying to store a certain line of a text file in a batch file with this code.

for /f "tokens=* delims= " %%a in (files.txt) do (
set /a N+=1
set v[!N!]=%%a
)

set /p id="Please choose a number(1-10):"

set number=%v[id]%

echo %number%

endlocal

However instead of printing out the line it prints out

id

Could someone help with this?

  • 1
    Change this line: `set number=%v[id]%` by this one: `set number=!v[%id%]!`. See: http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990 – Aacini Jul 20 '16 at 05:01
  • Thank you so much, that fixed my problem! – Chimichanga Jul 20 '16 at 05:11

1 Answers1

0

Like what Aacini said I changed the line

set number=%v[id]% 

by this one

set number=!v[%id%]!

and it worked

Community
  • 1
  • 1