Set an environment variable from a text file contentTag(s): Misc Prog HowTo

Let's say we have the following text file.

[howto.txt]

this is an interesting howto
This batch file will read the given file and set the environment variable content with the file content.

[howoto.cmd]

@echo off
SetLocal EnableDelayedExpansion
set content=
for /F "delims=" %%i in (howto.txt) do set content=!content!%%i
echo %content%
EndLocal
gives this output
> howto.cmd
this is an interesting howto



If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2012
[ home ]