I need to read a txt-file in batch script, save every line to variable and use it when delayed expansion is enabled. But the text file can contain exclamation marks, and they should be treated as usual text. I tried this code:
@echo off
setlocal
set file1=C:\BatchTest\TEXT.txt
set "WasFirstLineRead1="
setlocal disabledelayedexpansion
for /f "delims=" %%i in (%file1%) do (
set "line=%%i"
if defined WasFirstLineRead1 (
endlocal
)
setlocal enabledelayedexpansion
echo !line!
set "line="
endlocal
setlocal disabledelayedexpansion
set "WasFirstLineRead1=YES"
)
endlocal
pause
But it doesn't update the value of the variable line
after parsing the first line, it always contains the first line. How can it be fixed?
For example, the txt-file contains this text:
,"H!e!l!l!o! world!,"
,"H!e!l!l!o! "H!e!l!l!o!
world!," world!,"
world!," "H!e!l!l!o!
The output should be the same, but the actual output is
,"H!e!l!l!o! world!,"
,"H!e!l!l!o! world!,"
,"H!e!l!l!o! world!,"
,"H!e!l!l!o! world!,"