Robocopy - 比较文件的修改日期?

发布于 2024-09-02 13:54:24 字数 170 浏览 2 评论 0原文

我一直在尝试创建这个脚本,该脚本基本上镜像两组文件夹及其内容(包括子文件夹),但仅复制比已存在的文件更新的文件。我尝试通过编写 vbscript 来做到这一点,但事实证明我需要手动扫描每个子文件夹,然后扫描它的内容。然后是该子文件夹的内容等等。

所以我想知道是否有人知道这是否可以用 Robocopy 来完成?

I've been trying to create this script that basically mirrors two sets of folders and it's content (including subfolders), but only copy files that are newer than the ones that already exist. I tried doing this by writing a vbscript, but it turns out that I manualle need to scan each subfolder and then it's content. And then that subfolder's content as well and so on and so forth.

So I'm wondering if anyone knows if this can be done with Robocopy?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾城泪 2024-09-09 13:54:24

ROBOCOPY %SOURCE_DIR% %TARGET_DIR% * /MIR

更正

ROBOCOPY %SOURCE_DIR% %TARGET_DIR% * /MIR /XO

ROBOCOPY %SOURCE_DIR% %TARGET_DIR% * /MIR

CORRECTION

ROBOCOPY %SOURCE_DIR% %TARGET_DIR% * /MIR /XO

不即不离 2024-09-09 13:54:24

简而言之 - 是的 - RoboCopy 非常好且简单。默认情况下,它只复制已更改的文件,并且不会复制未更改的文件。您只需添加一个参数即可使其排除目标存在且较新的文件。

RoboCopy 的语法有点奇怪,因此您可能需要从此处阅读更多内容。

您可能想要这样的内容:

RoboCopy.exe %sourceDir% %targetDir%\ *.* /xo

%sourceDir% - 您的源目录

%targetDir% - 您的目标目录

*.* - 中的文件要复制的源目录

/xo - 如果目标已存在且较新,则排除文件。

[编辑回应评论]

如果您说要从目标目录中删除源目录中不再存在的文件,那么我相信开关 /purge这样做。

In short - yes - this is nice and simple with RoboCopy. By default it only copies changed files anyway, and won't bother copying unchanged files. You just need to add one argument to get it to exclude files where the destination exists and is newer.

The syntax of RoboCopy is a little bit quirky, so you may want to read more from here.

You probably want something like this:

RoboCopy.exe %sourceDir% %targetDir%\ *.* /xo

%sourceDir% - your source directory

%targetDir% - your target directory

*.* - the files in the source directory to copy

/xo - exclude file if the destination already exists and is newer.

[Edit in response to comment]

If you are saying you want to remove files from the destination directory that no longer exist in the source directory, then I believe the switch /purge does this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文