I have a file report.txt having comma separated values like (1,2,3,4). I am checking if the file is not blank then assign the 4 variables with values in the file. But the va
You've enabled delayed expansion, but you aren't using it. In order to use delayed expansion, you need to use !variable!
instead of %variable%
. Additionally, the variable specified in for
loops is case-sensitive, so you either need to set var1 equal to %%A
or use %%a
as the loop variable.
setlocal enabledelayedexpansion
for /f %%i in ("Report.txt") do set size=%%~zi
if %size% gtr 0 (
for /F "tokens=1-4 delims=," %%a in (Report.txt) do (
set "var1=%%a"
set "var2=%%b"
set "var3=%%c"
set "var4=%%d"
)
set var
)
echo !var1!
setlocal enabledelayedexpansion
for /f %%i in ("Report.txt") do set size=%%~zi
if %size% gtr 0 (
I changed the code as below and it started working. Thank you guys for your time. Appeciate it.
for /F "tokens=1-4 delims=," %%A in (%cd%\Report.txt) do (
set "var1=%%A"
set "var2=%%B"
set "var3=%%C"
set "var4=%%D"
)
set var
)
echo !var1!