1/4/2018
Posted by 
Batch Read Line From File Into Variable Rating: 4,4/5 2961votes

Hi, I have a text file that has four lines of text as follows: Hello Planet Welcome Goodbye I have a batch file that I would like to read in each line and set each line to a variable. For example my batch file is as follows: set /p hostname=. Nicole Ray She Half My Age more.

Batch Read Line From File Into Variable

Get the first line of a text file and set it to a variable in. Putting it into the Text.txt file. Trying to read a text file content and set variables values. Parsing a string variable in a batch file for LAPS / ADU&C. Read lines from a file into command.

This will read a file into an array and assign each line into a variable and display them @echo off set 'File2Read=file.txt' If Not Exist '%File2Read%' (Goto:Error) rem This will read a file into an array of variables and populate it setlocal EnableExtensions EnableDelayedExpansion for /f 'delims='%%a in ('Type '%File2Read%') do ( set /a count+=1 set 'Line[!count!]=%%a' ) rem Display array elements For /L%%i in (1,1,%Count%) do ( echo 'Var%%i' is assigned to ==^>'!Line[%%i]!' ) pause>nul Exit::***************************************************:Error cls & Color 4C echo( echo The file '%File2Read%' dos not exist! Pause>nul exit /b::***************************************************.