copy all files recursively into a single folder (without recreating folders)

Basj picture Basj · Mar 4, 2013 · Viewed 12.8k times · Source

With a batch (.bat), I want to copy all mp3 files that are in 1 subdirectory of D:\TEMP

D:\TEMP\\(anyfolder)\\(anyfile.mp3)

to

E:\MYFOLDER\

I tried with xcopy but

  • I don't know how to tell "just recurse subfolders of D:\TEMP and not subsubfolders, subsubsubfolders, etc."

  • When using xcopy, folders are created in the destination (in order to replicate source's folder tree), I don't want this : files should be copied in just 1 single folder.

Thanks in advance!

Answer

PA. picture PA. · Mar 4, 2013

for command is your friend. Read help for and then try this in the command prompt

for /d %a in (*) do @echo %a

as you see, it follows all subfolders in the current directory.

thus,

for /d %a in (*) do @copy %a\*.mp3 e:\myfolder

will copy all your mp3 to the destination folder.