0

I see that there are different related questions (e.g. this or this other), but none seems to deal with my problem. I am trying to copy all the PDF files that I have in subfolder into the current folder.

The following command works well if I put the .bat file and subfolder on the Desktop:

for /R "%cd%\subfolder" %%f in (*.pdf) do copy %%f ".\"

However, if I put the subfolder and the .bat file in a position characterized by longer path, the script doesn't work anymore. The path has spaces and underscores, no special characters.

Any help would be highly apppreciated.

Community
  • 1
  • 1
Stefano Lombardi
  • 1,581
  • 2
  • 22
  • 48

1 Answers1

2

If the path can have a space in it, then it must be quoted. Since all paths -could- contain a space character, always use quotes.

for /R "%cd%\subfolder" %%f in (*.pdf) do copy "%%~f" ".\"

Edit: Used "%%~f" as suggested by @aschipfl.

lit
  • 14,456
  • 10
  • 65
  • 119