Escape parentheses in nested batch for loop?
I have a folder which contains an unknown number of .txt files named as such:
todo.txt todo (1).txt todo (2).txt todo (3).txt
I’m running this command to iterate through the files and print the text on each line within the files:
for /r %f in (test\*.txt) do (for /f %p in (%f) do echo %p)
/r returns the file names correctly and /f will output each line of text in todo.txt but when it hits
todo (1).txt it performs the command
for /f %p in (C:\test\todo (1).txt) do echo %p and errors out saying
The system cannot find the file C:\test\todo.
How do you escape parentheses in this situation?
usebackq option to allow you to double-quote the filename
for /r %f in (test\*.txt) do (for /f "usebackq" %p in ("%f") do echo %p)
Answered By – npocmaka