xcopy directories and subdirectories recursively and filter only filenames by extension

DxCK picture DxCK · Jun 1, 2010 · Viewed 60.5k times · Source

Here is what i have for now:

xcopy "c:\projects\SampleProject" "c:\temp\copytest" /E /H /EXCLUDE:elist.txt

It does all the job i need except filtering filenames by extensions.

For example: copy all *.exe files from c:\temp\copytest and subdirectories.

How to do that?

Answer

pollirrata picture pollirrata · Apr 23, 2013

I happened to need this too, and found out that if you want to xcopy files with specific type to a new folder keeping the current folder structure you need only to do this

xcopy [SourcePath]*.mp3 [DestinationPath]  /sy

/s: Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory.

/y : Suppresses prompting to confirm that you want to overwrite an existing destination file

Documentation