xcopy files into single directory

I'd like to use xcopy on a Windows machine to pull out all files with .png extension into a single directory.

I tried xcopy C:\folder\*.png /s C:\png\, but it is keeping the sub-directories inside \folder, (for example in C:\png, there is C:\png\a\b\c\img.png) which I don't want. I simply want all .png inside C:\png without it retaining the directory structure that was in C:\folder.


This can be done with good old for:

for /r C:\Folder %f in (*.png) do @copy "%f" C:\png

Nothing fancy.


If you have cygwin installed, this would be a job for find:

cp `find /cygdrive/c/folder/* -name '*png'` /cygdrive/c/png/

(though that will have trouble if any of the filenames have spaces in them - you'll find some variant of a find command that will work in all circumstances though)

If you are running Vista, 2003 or 2008 then the less flexible but still useful "forfiles" is your friend. Something like:

FORFILES /P c:\folder\ /M *.png /S /C "cmd /c copy @file c:\png\"

Note: I've not tested either of the above commands, but in theory they should work...