2
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

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
1
  • The ~ in %~f is not required.
    – DavidPostill
    Jan 20 '19 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.