How can I recursively copy files of a specific pattern into a single flat folder on Windows? How can I recursively copy files of a specific pattern into a single flat folder on Windows? windows windows

How can I recursively copy files of a specific pattern into a single flat folder on Windows?


mkdir targetDirfor /r %x in (*.dll, *pdb) do copy "%x" targetDir\

Use /Y at the end of the above command if you are copying multiple files and don't want to keep answering "Yes".


command XCOPY

example of copying folder recursively:

mkdir DestFolderxcopy SrcFolder DestFolder /E

(as stated below in the comment following WIKI that command was made available since DOS 3.2)


Make sure that you have the quotes right if you have spaces in your path.

This is my postbuild event for my TFS build server (that is why there is "%%"). I needed all the test files to be copied over.

if not exist  "$(TargetDir)..\SingleFolderOutput" mkdir -p "$(TargetDir)..\SingleFolderOutput"for /r **%%x** in (*.dll, *.pdb, *.xml, *.xaml, *.exe, *.exe.config) do xcopy **"%%x"** "$(TargetDir)..\SingleFolderOutput" /Y