ROBOCOPY - 复制文件夹的内容到一个文件夹 [英] ROBOCOPY - Copy folders content to a single folder

查看:1071
本文介绍了ROBOCOPY - 复制文件夹的内容到一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一些code我做:)

Here is some code I made :)

@echo off
set source="R:\Contracts\"
set destination="R:\Contracts\Sites\"
ROBOCOPY %source% %destination% *.srt *.pdf *.mp4 *.jpg /COPYALL /R:0 /S
for /r %source in (*) do @copy "%destination" .

R:\\合同\\充满这在他们的文件夹

R:\Contracts\ is full of folders which have files in them.

我要复制所有R:\\合同\\网站\\和扁平的文件夹结构

I want to copy all to R:\Contracts\Sites\ and flatten the folder structure.

拷贝一切良好,但也文件夹结构。

Everything copies well but also the folder structure.

感谢您

推荐答案

没有单一的命令将扁平化层级你;你将不得不使用多个命令。它可以简单地通过使用/ R走路层次,再加上你的复制/移动选择(移动,复制,XCOPY,的Robocopy)的命令来完成。因为你的目的地是源分层结构中,您从一个源需要一个IF至prevent目的地。

No single command will flatten the hierarchy for you; you will have to use multiple commands. It can be done simply by using FOR /R to walk the hierarchy, coupled with your copy/move command of choice (move, copy, xcopy, robocopy). Because your destination is within the source hierarchy, you need an IF to prevent the destination from being a source.

在继续,你应该停下来想想,如果相同的文件名出现在多个源文件夹会发生什么。你只能在你的目标文件夹一个版本。你能保证没有重复的名字存在吗?如果不是,哪些文件应该被保存在哪里?怎样组织指挥,让你想要的文件?这种并发症可能是为什么没有命令写过简单地扁平化层次。

Before proceeding you should stop and think about what happens if the same file name appears in multiple source folders. You can only have one version in your destination folder. Can you guarantee no duplicate names exist? If not, which file should be kept? How can you structure the command to keep the file you want? This complication is probably why no command was ever written to simply flatten a hierarchy.

下面是您ROBOCOPY命令与FOR / R解决方案集成。

Here is your ROBOCOPY command integrated with the FOR /R solution.

@echo off
set source="R:\Contracts"
set destination="R:\Contracts\Sites"

::Not sure if this is needed
::It guarantees you have a canonical path (standard form)
for %%F in (%destination%) do set destination="%%~fF"

for /r %source% %%F in (.) do if "%%~fF" neq %destination% ROBOCOPY "%%F" %destination% *.srt *.pdf *.mp4 *.jpg /COPYALL /R:0

这篇关于ROBOCOPY - 复制文件夹的内容到一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆