loop without for to read lines of a file
Posted: 15 Jul 2020 05:53
I use following to read from a file but it does not continue reading after first line.
I do not want to use a for-loop and want to experiment with set/p.
So, how could i achieve reading from a file in a loop(without for-loop)? I tried staged redirection but failed.
I tried with call but it hits stack limit after 338 lines of text.
I do not want to use a for-loop and want to experiment with set/p.
So, how could i achieve reading from a file in a loop(without for-loop)? I tried staged redirection but failed.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "ndx=0"
(
:loop
echo loop index: !ndx!
set val=
set /a ndx=ndx+1
set /p val=
if "!val!"=="" (goto :exitLoop)
set a!ndx!=!val!
echo !val!
goto :loop
) <variables.txt
:exitLoop
echo after loop
echo a1: !a1!
echo a2: !a2!
endlocal
Code: Select all
setlocal EnableDelayedExpansion
set "ndx=0"
(
:loop
echo loop index: !ndx!
set val=
set /a ndx=ndx+1
set /p val=
if "!val!"=="" (goto :exitLoop)
set a!ndx!=!val!
echo !val!
call :loop
exit /b
) <variables.txt
:exitLoop
echo after loop
echo a1: !a1!
echo a2: !a2!
endlocal