In Windows, a batch file with a recursive for loop and a file name including blanks
- by uvts_cvs
Hello,
I have a folder tree, like this (it's only an example, it will be deeper in my real case):
C:\test
|
+---folder1
| foo bar.txt
| foobar.txt
|
+---folder2
| foo bar.txt
| foobar.txt
|
\---folder3
foo bar.txt
foobar.txt
My files have one or more spaces in the name and I need to perform a command on them, so I am interested in foo bar.txt but not in foobar.txt.
I tried (inside a batch file):
for /r test %%f in (foo bar.txt) do if exist %%f echo %%f
where the command is the simple echo.
It does not work because the space is skipped and I get no output.
This works but it is not what I need:
for /r test %%f in (foobar.txt) do if exist %%f echo %%f
It prints:
C:\test\folder1\foobar.txt
C:\test\folder2\foobar.txt
C:\test\folder3\foobar.txt
I tried using the quotation mark (") but it does not work:
for /r test %%f in ("foo bar.txt") do if exist %%f echo %%f
It does not work because the quotation mark is still included in the output:
C:\test\folder1\"foo bar.txt"
C:\test\folder2\"foo bar.txt"
C:\test\folder3\"foo bar.txt"