I want to copy all files of a certain type (like .docx, .pdf, etc) on my PC into a folder. How can I do that?

  • You may want to mention which operating system you're using. By your use of "PC" I assume a flavor of Windows? Isn't something like copy *.pdf c:\myfolder sufficient? Sep 29, 2012 at 17:09
  • PC refers to hardware not OS. Sep 29, 2012 at 22:17
  • find . \( -iname "*.pdf" -o -iname "*.docx" \) -print0 | xargs -0 cp -t thefolder This will work on any Posix compliant OS: Gnu/Linux, OS X, BSD, Solaris, Unix, or even Microsoft windows with gnu tools installed. Sep 29, 2012 at 22:20

2 Answers 2


Perhaps the simplest option is to use Windows Search from whichever drive you wish to copy the files from (or from My Computer if you want to find them across all of your drives). Type *.pdf into the search field at the top right of an Explorer window. Once it finishes finding everything, press Ctrl+a, then Ctrl+c. Navigate to your destination folder, then Ctrl+v. This will allow you to have all of the files in that one directory (no subdirectories).

Another option is Robust Copy (robocopy), which will create a mirrored folder structure of the files it finds into the destination folder:

robocopy C:\ C:\OutputFolder *.pdf /S /R:1 /W:1 /NDL /XJD /XD OutputFolder /L

If your PC does not have this command, it is available as part of the Windows 2003 Server Resource Kit here.

Change C:\OutputFolder accordingly to whatever directory you want. A quick overview of what these options are doing:

  • C:\ this is the source that is to be searched.
  • C:\OutputFolder this is the destination into which the files will be copied.
  • /L will LIST all the files that will be copied; the command won't actually copy anything with this option present. This way you can review the files that will be copied, how many there are, total size, etc. To allow the files to be created, simply re-run the command without /L.
  • /S recurses all subdirectories under the provided source, "C:\".
  • /R:1 (optional) will retry any failed copy events once.
  • /W:1 (optional) will wait one second after an event fails.
  • /NDL (optional) will prevent directories from being listed.
  • /XJD (required) will prevent Directory Junction Points from being parsed. This avoids a nasty recursion issue that can sometimes occur with Windows' "fake" directories such as "Documents and Settings".
  • /XD OutputFolder (required) will prevent Robocopy from re-copying files that have already been placed into your OutputFolder.

Run this command to copy all PDF files from the C drive and subdirectories to C:\allPDF folder.

C:\>for /R %G IN (*.pdf) DO xcopy "%G" \allPDF

You can do the same with any other format.

  • 1
    A problem: for /R %G IN (*.pdf) DO ... will treat \allPDF\*.pdf as well. Possibly circular reference...
    – JosefZ
    Jun 7, 2015 at 20:44

You must log in to answer this question.

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