Question on Simple nested FOR
Posted: 16 Jun 2016 21:30
Hi
I have a text file named "All Files.txt" containing a list of another csv files.
I want to get a variable that contains each row value in the nested FOR of the csv files listed in "All Files.txt"
Let me show my code and the output
The content of each file is:
The output I got from my code is show here:
What I'm expecting is getting for the "echo inside" the content of the csv files but instead I'm getting the content of the txt file.
How can I get the content of each row in the nested FOR of the csv files in a variable Tem for further treatment?
Did I miss something?
Please share your thoughts
Thank you in advance
I have a text file named "All Files.txt" containing a list of another csv files.
I want to get a variable that contains each row value in the nested FOR of the csv files listed in "All Files.txt"
Let me show my code and the output
Code: Select all
@echo on
setlocal EnableDelayedExpansion
for /F "tokens=*" %%B in ("All Files.txt") do (
set Tem=
for /F "tokens=*" %%a in ("%%B") do (
set Tem="%%a"
echo Var=%%a
echo inside=!Tem!
)
echo outside=!Tem!
)
The content of each file is:
Code: Select all
D:\Test\Test2>type "All Files.txt"
File One.csv
File Two.csv
File Three.csv
D:\Test\Test2>type "File One.csv"
Test One,10
Test Five,8
Test Seven,3
Test Ten,2
Test Eleven,20
D:\Test\Test2>type "File Two.csv"
Test Four,5
Test Six,1
Test Nine,21
Test Twelve,40
Test Twenty,10
Test Twenty One,1
Test Twenty four,4
D:\Test\Test2>type "File Three.csv"
Test One,1
Test Two,3
Test Four,7
D:\Test\Test2>
The output I got from my code is show here:
Code: Select all
D:\Test\Test2>Test3.bat
D:\Test\Test2>setlocal EnableDelayedExpansion
D:\Test\Test2>for /F "tokens=*" %B in ("All Files.txt") do (
set Tem=
for /F "tokens=*" %a in ("%B") do (
set Tem="%a"
echo Var=%a
echo inside=!Tem!
)
echo outside=!Tem!
)
D:\Test\Test2>(
set Tem=
for /F "tokens=*" %a in ("All Files.txt") do (
set Tem="%a"
echo Var=%a
echo inside=!Tem!
)
echo outside=!Tem!
)
D:\Test\Test2>(
set Tem="All Files.txt"
echo Var=All Files.txt
echo inside=!Tem!
)
Var=All Files.txt
inside="All Files.txt"
outside="All Files.txt"
D:\Test\Test2>
What I'm expecting is getting for the "echo inside" the content of the csv files but instead I'm getting the content of the txt file.
How can I get the content of each row in the nested FOR of the csv files in a variable Tem for further treatment?
Did I miss something?
Please share your thoughts
Thank you in advance