Here is a for loop to save each line of a text file to its own variable:
@echo off
setlocal enableextensions enableDelayedExpansion
set count=0
for /f "tokens=*" %%a in (file.txt) do (
set /a count=!count! + 1
set var_!count!=%%a
)
endlocal
I would like to save the content of each variable to a separate new text file. How can I do this? I tried the following. But it does not work, because !var_!count!! is a variable inside a variable.
@echo off
setlocal enableextensions enableDelayedExpansion
set count=0
for /f "tokens=*" %%a in (file.txt) do (
set /a count=!count! + 1
set var_!count!=%%a
echo !var_!count!!>file_!count!.txt
)
endlocal