Loading a Single Line of a txt files into a Variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rimal7
Posts: 2
Joined: 02 Sep 2007 06:20
Location: hAMILTON, ONTARIO

Loading a Single Line of a txt files into a Variable

#1 Post by Rimal7 » 02 Sep 2007 06:39

Hi,

I have an txt File that contains a single line of text, and I want to load the txt string from the TXT file into a DOS Batch variable then Concat the string to the section of the string that I need.

Filename: InvoiceNumber.txt

I have no idea where to start, could someone please help.

Thanks,



Rimal 7
DOS Batch Newbie

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 07 Sep 2007 23:10

Rimal7,

To get the string from the file use the "for /f" command.

Code: Select all

REM The "for /f" command reads a line from a file
for /f "delims=" %%a in (InvoiceNumber.txt) do set "TxtFromFile=%%a"
REM Now concatenate as desired
set "txt=Hi, this is from the InvoiceNumber.txt file: %TxtFromFile%"
echo.%txt%


DosItHelp? :wink:

Rimal7
Posts: 2
Joined: 02 Sep 2007 06:20
Location: hAMILTON, ONTARIO

Loading from a TXT file

#3 Post by Rimal7 » 10 Sep 2007 09:12

Worked Beautifully

Thanks for your help,


Rimal 7

Post Reply