FOR /F %%A IN ('type %INPUT%') DO echo %%A
' in the brackets will cause to execute the statement and uses the output like a file source
Question
I have a batch script that would concatenate the content of files that were listed in an index file. It used to work until there were spaces in the paths. I have edited it a bit, but it is something like this:
SET INPUT="C:\Has Spaces In Path\indexfile.txt"
SET ROOT="C:\Has Spaces In Path\inputdirectory\"
SET OUTPUT="C:\Has Spaces In Path\outputdirectory\mergedfile.txt"
FOR /F %%A IN (%INPUT%) DO TYPE "%ROOT%%%A" >> "%OUTPUT%"
The problem I have is that %INPUT% now appears to get tokenised in the for loop and if I put quotes around it (i.e. "%INPUT%") it does not work either. Is there any way I can get this loop to iterate over each line in the file specified by INPUT and concatenate the contents to the OUTPUT file?
Thanks.
Edit: Based on the answer, this did what I wanted:
FOR /F %%A IN ('type "%INPUT%"') DO TYPE "%ROOT%%%A" >> "%MERGED%"
Solution
FOR /F %%A IN ('type %INPUT%') DO echo %%A
' in the brackets will cause to execute the statement and uses the output like a file source
OTHER TIPS
FOR /F "usebackq" %%A IN ("%INPUT%") DO TYPE "%ROOT%%%A" >> "%OUTPUT%"
or, better yet:
(FOR /F "usebackq" %%A IN ("%INPUT%") DO TYPE "%ROOT%%%A") > "%OUTPUT%"
For further details, see: FOR /?