简体   繁体   中英

Windows Command Copy all files recursively to a Main Folder

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"

要将当前文件夹及其子目录中的所有文件复制到当前文件夹的父文件夹,您可以使用:

for /r . %a in (*) do copy %a ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM