Just adding CALL may solve your problem. (also invalid VersionNumber definition)
SET VersionNumber=7.0 FOR /F "eol=; delims=" %%I IN (TargetFolders.txt) DO ( call echo Folder: %%I )
But this will fail if your file contains unquoted special characters such as & , > , < , | .
For example, the following line will not be executed:
%ProgramFiles%\This&That\ %VersionNumber%
It will work if specified
"%ProgramFiles%\This&That\" %VersionNumber%
CALL will also cripple any quotation marks: "^" will become "^^"
The best solution would be to change your text file and replace every % with ! .
!ProgramFiles!\Acme\FooBar !VersionNumber! !ProgramFiles!\This&That !VersionNumber!
Now you can safely use the delayed extension to expand the variables inside the loop.
setlocal enableDelayedExpansion SET VersionNumber=7.0 FOR /F "eol=; delims=" %%I IN (TargetFolders.txt) DO ( echo Folder: %%I )
If your text file already has ! which you want to save, it must be escaped. Also ^ must be escaped if it appears on line with ! .
preserve caret ^^ and exclamation ^! by escaping caret ^ without exclamation is no problem
Alternatively, you can replace variables for carriage and exclamation letters
alternate method to preserve caret !c! and exclamation !x! caret ^ without exclamation still no problem
And then define the variables in your batch
setlocal enableDelayedExpansion set "x=^!" set "c=^" SET VersionNumber=7.0 FOR /F "eol=; delims=" %%I IN (TargetFolders.txt) DO ( echo Folder: %%I )