.bat文件自动复制 - 如何只复制文件一次? [英] .bat file autocopy - how to only copy file once?

查看:445
本文介绍了.bat文件自动复制 - 如何只复制文件一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个.bat文件,将所有文件和文件从一个文件夹自动复制到另一个文件夹。例如:

I want a .bat file that will copy all files and folders from one folder to another folder automatically. For example:

robocopy "c:\source" "D:\target" /e /MON:1 /xc /xn /xo

但是我需要它使得一旦一个文件被复制时,该文件将不被再次复制,即使在复制已被移动到不同的目录。有没有办法做到这一点?是否有可能进行的Robocopy创建日志和复制文件之前检查该?

However I need it so that once a file has been copied, that file will not be copied again, even if the copy has been moved to a different directory. Is there any way to do this? Is it possible for robocopy to create a log and check against that before copying the file?

如果使用Robocopy不能做到这一点,又能怎样?

If robocopy can't do it, what can?

推荐答案

使用额外的选项 / M 你的的Robocopy (SS64文章)命令由斯蒂芬<建议线/一>,因为这将导致只复制文件与源文件夹树中设置存档属性,并通过删除存档属性的的Robocopy 成功后复制文件。

Use additionally the option /M on your robocopy (SS64 article) command line as suggested by Stephan because this results in copying only files with archive attribute set in source folder tree and removing archive attribute by robocopy after successful copying the file.

%SystemRoot%\System32\robocopy.exe "C:\source" "D:\target" /M /E /MON:1 /XC /XN /XO

存档属性会自动对文件修改后重新设置。

The archive attribute is automatically set again on file modification.

您或许还可以使用 XCOPY (SS64文章):

You could perhaps also use xcopy (SS64 article):

%SystemRoot%\System32\xcopy.exe "C:\source" "D:\target\" /M /E /C /I /Q /G /H /R /K /Y >nul

重要的是你的任务再次选择 / M 复制仅文件与源文件夹树中设置存档属性和清除复制文件后归档属性。

Important for your task is again option /M for copying only files with archive attribute set in source folder tree and clearing the archive attribute after copying the file.

请注意: / I ,无用户提示只用一个反斜杠目标文件夹路径结束工作原理

Note: /I works without user prompt only with target folder path ending with a backslash.

在命令提示符窗口中运行的Robocopy /?分别为 XCOPY /?有关其他选项的详细信息或读微软对单证的Robocopy 并的 XCOPY

Run in a command prompt window robocopy /? respectively xcopy /? for details on the other options or read the Microsoft documentations for robocopy and xcopy.

这篇关于.bat文件自动复制 - 如何只复制文件一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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