Copy Files with Same Extension from Subfolders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
johnbil
Posts: 11
Joined: 06 Jul 2013 09:01

Copy Files with Same Extension from Subfolders

#1 Post by johnbil » 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)? :?:

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Copy Files with Same Extension from Subfolders

#2 Post by Squashman » 07 Sep 2018 12:14

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.

johnbil
Posts: 11
Joined: 06 Jul 2013 09:01

Re: Copy Files with Same Extension from Subfolders

#3 Post by johnbil » 08 Sep 2018 15:34

Thanks, Squashman. That did it.

Post Reply