Recursively copy files that match a wildcard combination but not create the directory tree in DOS

BZ1 picture BZ1 · Sep 16, 2011 · Viewed 10.3k times · Source

I found that I can use xcopy /s to copy all files that match a wildcard combination in a folder to another location. But this command re-creates the folder structure. I do not want the tree. I need just the files dumped into the destination folder. There are no duplicate files in the source folder.

Answer

Sergey Podobry picture Sergey Podobry · Sep 16, 2011

You can use for command:

for /R %%x in (*.cpp) do copy "%%x" "c:\dest\"

If you want to run it directly from command prompt (not from a batch file) use %x instead of %%x.