Moving large quanities of files from inside folders to one master file

Experts: I have hundreds of PDF documents inside multiple folders (one case=PDF file of about 100 pages per case); I'd like to copy all of the pdfs (about 1000 cases that inside each folder (1000 folders) into one master folder of just the pdf docs. So the structure is:
1 file case # 12345 in folder #1 contains 1 pdf; next folder is pdf #12346, next folder is pdf #123457. I need to extract every pdf inside each folder (again, 1000 folders) and move them all into one singular folder for batch operations on all of the pdf files (1000 files). Any suggestion on the easiest way to extract them all from each folder and put all of the PDFs into one master folder together? The pdfs should be sequential, i.e. not in folders when completed, in one folder. Any suggestions?? Thanks all.

Much appreciated.
Who is Participating?
BillDLConnect With a Mentor Commented:
Thanks satzm

In that case a simple copy command should work for you.  It's so easy it's criminal ;-)
I am at work in a non-IT environment and cannot test this though.

1. Create a new destination folder where you want all the PDF files, ie. your Master Folder.
2. Copy the text in the code snippet below, paste into Windows Notepad, and then change the path shown as "C:\Path_To\PDFs" to the top line folder containing all the sub-folders with your PDF files.
3. File menu > Save As > Navigate to the new "master folder" you created, and name the file "CopyPdfs.cmd"
(the file name isn't important, but be sure to name it with the  .CMD  file extension, because this is your batch script).
4. Double-Click on the "CopyPdfs.cmd" file.

The command walks down through all the sub-folders starting at the top level folder specified, and copies all PDF files it finds into the same folder as the batch file, which will be your new master folder.

@echo off
for /r "C:\Path_To\PDFs" %%A in (*.pdf) do (
    echo Copying "%%~nxA"
    copy /-Y /V "%%A"

Open in new window

The /V switch means "Verify that files are written correctly", which will slow the process down but is probably a good idea to leave.  The /-Y switch forces it to prompt if an overwrite would occur.
Tony GiangrecoCommented:
Use a simple batch file like this

md newpdfs
xcopy c:\Casepdfs\*.pdf  c:\newpdfs /s

It will go through the entire structure of your folders and copy all PDF's found into a new folder.
Hi satzm

TG-TIS has suggested the easiest method to achieve this, but the  /S  switch copies folders and sub-folders to the destination, which is not what you want.  You want all the PDF files in one destination folder minus the original source directory structure.

Do you know whether there are two or more PDF files with the same file names in different source folders?

That will make a difference, because otherwise the first one copied will be overwritten by subsequent ones copied unless the batch file is written to take account of this.
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tony GiangrecoCommented:
I have found a replacement utility that does perform the copy process, searches through all folders in the search path and writes all files to one destination folder with no sub-folders. It also has the option of added the original folder name it was copied from which is handy if you have duplicate file names in different folders.

Here is information on the utility and how to dowbnload it.

Search and collect files into just one directory.

In many cases, collecting certain files into a directory may save a
  lot of time.  For example, if you gather all Microsoft Word document
  (.DOC) files from the entire volume into just one subdirectory,
  browsing them and locating a particular file become much easier.
  That is what XXCOPY's /SX, /SG and their variations are for.

  The traditional way to do this is (don't type beyond the comment //... ),

     XCOPY  C:\*.doc  D:\mydocs\   /S       // using Microsoft's XCOPY
     XXCOPY C:\*.doc  D:\mydocs\   /S       // the same here with XXCOPY

       The /S switch makes the copy operation to recursively
       go inside subdirectories and copy all matching files.
       If subdirectories are not present in the destination,
       they will be created as needed.

         Note that the destination directory was deliberately
         chosen in a different drive in the examples above.
         Watch out if the destination is in the same volume...

           XCOPY  C:\*.doc  C:\mydocs\   /S       // a FATAL error
           XXCOPY C:\*.doc  C:\mydocs\   /S /CCY

         This is a classic case of the cyclic copy situation which
         Microsoft's XCOPY cannot handle.  Using /CCY, our XXCOPY
         allows you to specify the destination in the same volume.
         See XXTB #07 for detail.

     Although the files you wanted are all copied into the destination,
     the destination directory will inevitably have many subdirectories
     which makes your next step still very time-consuming.

XXCOPY provides better solutions.

  XXCOPY has a better way to deal with the situation that avoids making
  subdirectories in the destination.  Of course, it is inevitable that
  many files share the same filename.  So, XXCOPY synthesizes new
  names when duplicate files are to be copied into the destination.

     XXCOPY C:\*.doc  D:\mydocs\   /SX
     XXCOPY C:\*.doc  D:\mydocs\   /SG

  Our original directory-flattening functions (/SX, /SL and /SR) combine
  the source directory path (only the distinguishing part) with the
  source filename to form a long filename which is always unique
  (and you can tell where the files are from).

      /SL     Flattens subdirectories, add-name-Left
      /SX     Flattens subdirectories, add-name-Middle
      /SR     Flattens subdirectories, add-name-Right

  By popular demand by XXCOPY users, we re-engineered the new file-gathering
  functions /SG and its variations which retain the original filename.

      /SG     same as /SGN (newest one and sorted by newness)
      /SGN    sorted, newest file first
      /SGO    sorted, oldest file first
      /SGF    unsorted, first come first served

      /SGNO   picks the newest file
      /SGOO   picks the oldest file
      /SGFO   picks the first file encountered

  That's a total of nine flavors to choose from!  Our favorite is /SGN
  which got the honor of being equivalent to its shorter version, /SG.

The /SX (/SL or /SR) switch flattens a directory.

  To understand how these schemes work, it is easiest to actually
  run the command and take a look at the destination directory.
  Let us start with the directory-flattening functions.

    XXCOPY C:\*.doc  D:\mydocs\   /SX     // puts path in the middle

       The result would be

       D:\mydocs\MYFILE`My Documents`word`.DOC
satzmAuthor Commented:
BillDi: The files (folders) definitively do not have the same names.  Each file is a separate case with a separate court case #.

TG-TIS, I am sorry, I am not an administrator on the network, so do not have authority (security settings) to add new programs to the network. I need to work this within a windows environment without adding additional programs (notwithstanding that program looks perfect :( but I can't use that answer).
satzmAuthor Commented:
BillDL: Thanks big time; that's the ticket! Much appreciated; this is why I subscribe to EE, you guys are great. Thanks again.
You're welcome satzm, but go easy on the compliments or we (me) will get big-headed ;-)
Glad you have a working solution to the problem.

What might be a good idea before you go deleting all the folders and sub-folders containing all the court case PDFs, is to verify that the files all copied.  Probably the easiest way would be to just select all the PDFs in your new master folder (Edit menu > Select All) and see how many PDF files it says are there (exclude the batch file that is probably still in that folder from the count).  Then run a DIR command on the top level folder where the PDFs were copied from and see how many PDF files it tells you are in those folders on the final lines.  Example:

dir /a-d /on /s "C:\Path_To\PDFs\*.pdf"

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.