for /R "c:\" %f in ("*.pdf") do xcopy %f "%USERPROFILE%\all\text" /s /c /d /e /h /i /r /y

This is the command I am using to copy all of the .pdf files on my computer into one folder. However, it does not copy the files from folders with spaces in them. I did my research already. I tried setting the "c:\" to "c:\*.*", yet it still does not work.

How can I copy all .pdf files without changing the names of the folder?

1 Answer 1


It appears you need to also put the double quotes around the %f variable placeholder after the xcopy command within the FOR /R loop so try the below and if it works, then that is your problem.

Command Line Version

for /R c:\ %f in ("*.pdf") do xcopy "%~f" "%USERPROFILE%\all\text" /s /c /d /e /h /i /r /y

Batch Script Version

for /R c:\ %%f in ("*.pdf") do xcopy "%%~f" "%USERPROFILE%\all\text" /s /c /d /e /h /i /r /y
  • The ~ in %~f is not required.
    – DavidPostill
    Jan 20, 2019 at 13:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .