Page 1 of 1

Copy Files with Same Extension from Subfolders

Posted: 07 Sep 2018 10:51
by johnbil
I am trying to create a batch file to copy files of one extension type from numerous subfolders to a different folder. I am using this command:

xcopy *.mp3 destination /s

It isolates the files and copies the files, but creates the subfolders too. Is there another option that would place the files in only ONE destination folder (no subfolders)? :?:

Re: Copy Files with Same Extension from Subfolders

Posted: 07 Sep 2018 12:14
by Squashman
johnbil wrote:
07 Sep 2018 10:51
I am trying to create a batch file to copy files of one extension type from numerous subfolders to a different folder. I am using this command:

xcopy *.mp3 destination /s

It isolates the files and copies the files, but creates the subfolders too. Is there another option that would place the files in only ONE destination folder (no subfolders)? :?:

Code: Select all

FOR /R "C:\source folder" %%G IN (*.mp3) DO copy "%%G" "C:\destination\"
But you will run into problems if you have the same file name in multiple sub folders.

Re: Copy Files with Same Extension from Subfolders

Posted: 08 Sep 2018 15:34
by johnbil
Thanks, Squashman. That did it.