How can I recursively copy files of a specific pattern into a single flat folder on Windows?

Viewed 96834

I need to copy a set of DLL and PDB files from a set of folders recursively into another folder. I don't want to recreate the folder hierarchy in the target folder. I want to use built in Windows tools, e.g. DOS commands.

6 Answers
mkdir targetDir
for /r %x in (*.dll, *pdb) do copy "%x" targetDir\

Use /Y at the end of the above command if you are copying multiple files and don't want to keep answering "Yes".

For gathering PBD files I end up with this:

cmd /q /c for /R "<your_source_folder>" %f in (*.pdb) do xcopy "%f" "<your_destination_folder>" /I /Y

I'm not aware of any command line tools that do this directly, but you could create a batch script to loop through sub folders, and copy the files you need.

However you may end up with files with duplicate filenames if you place them all in the same folder.

Related