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?

有帮助吗?

解决方案

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"

其他提示

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 ..
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top