Question

I was wondering if there is a quick and dirty command that can copy all files in a directory and it's subdirectory to another folder. The destination folder will have no subdirectories just all the source files.

Also as an added bit of fun, in case there is a file name conflict, not to overwrite but to rename the destination file with something unique, maybe append _1 to the filename?

Was it helpful?

Solution

This will copy the files and prompt if there is a filename conflict.

The third party tool XXcopy has the ability to flatten a directory tree and handle filename conflicts.

@echo off
for /r "d:\folder" %%a in (*) do copy "%%a" "E:\target folder"

OTHER TIPS

To copy for instance all files from the current folder and its sub directories to the parent folder of the current folder you can use:

for /r . %a in (*) do copy %a ..
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top