Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Variable to File Contents in Batch File 1

Status
Not open for further replies.

tekdudedude

Technical User
Sep 29, 2007
79
Hello,

I have a text file that is auto-generated which contains one line of data (less than 25 characters). In a simple batch file (.bat) how can set the value of a variable to the contents of that file?

Thanks,

TD
 
In a batch file, use the following line:

for /f "tokens=*" %%a in (text-file.txt) do set myvar=%%a

This will only work properly if there is ONE line of text in the text file. Further, the environment variable will only be valid during the cmd session - exit and start another command prompt and it's gone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top