Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 495
Basj Avatar asked Mar 04 '13 19:03

Basj


1 Answers

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.

like image 146
PA. Avatar answered Sep 20 '22 19:09

PA.