【问题标题】:Batch copy only modified files只批量复制修改过的文件
【发布时间】:2012-01-31 16:14:32
【问题描述】:

我有两个文件夹(比如 Source 和 Working)。现在,在这些文件/文件夹中,还有 100 多个其他文件/文件夹。

现在,文件夹 Source 会定期更新(即某些文件/文件夹可能会更改或添加)。我正在尝试使两个文件夹保持同步。

所以我需要一个批处理命令,这样只有“源”中新/修改的文件/文件夹才会更新到“工作”文件夹中。

【问题讨论】:

    标签: batch-file dos


    【解决方案1】:

    您不需要 bat 文件。只需使用带有一些参数的xcopy。试试:

    xcopy <path to source> <path to destination> /D /E /C /Q /H /R /Y /K 
    
    
    
    source  Specifies the file(s) to copy.
    destination Specifies the location or name of new files.
    /A  Copies only files with the archive attribute set, doesn't change the attribute.
    /M  Copies only files with the archive attribute set, turns off the archive attribute.
    /D:m-d-y    Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.
    /EXCLUDE:file1 [+file2][+file3]...  Specifies a list of files containing strings. When any of the strings match any part of the absolute path of the file to be copied, that file will be excluded from being copied. For example, specifying a string like \obj\ or .obj will exclude all files underneath the directory obj or all files with the .obj extension respectively.
    /P  Prompts you before creating each destination file.
    /S  Copies directories and subdirectories except empty ones.
    /E  Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T.
    /V  Verifies each new file.
    /W  Prompts you to press a key before copying.
    /C  Continues copying even if errors occur.
    /I  If destination does not exist and copying more than one file, assumes that destination must be a directory.
    /Q  Does not display file names while copying.
    /F  Displays full source and destination file names while copying.
    /L  Displays files that would be copied.
    /H  Copies hidden and system files also.
    /R  Overwrites read-only files.
    /T  Creates directory structure, but does not copy files. Does not include empty directories or subdirectories. /T /E includes empty directories and subdirectories.
    /U  Copies only files that already exist in destination.
    /K  Copies attributes. Normal Xcopy will reset read-only attributes.
    /N  Copies using the generated short names.
    /O  Copies file ownership and ACL information.
    /X  Copies file audit settings (implies /O).
    /Y  Suppresses prompting to confirm you want to overwrite an existing destination file.
    /-Y Causes prompting to confirm you want to overwrite an existing destination file.
    /Z  Copies networked files in restartable mode.
    /B  Copies the Symbolic Link itself versus the target of the link.
    /J  Copies using unbuffered I/O. Recommended for very large files.
    

    【讨论】:

    • 嗯..非常感谢...您能否解释一下具体参数,以确保仅复制修改后的文件/文件夹..
    • 请看xcopy中提供的链接:computerhope.com/xcopyhlp.htm
    • 我正在尝试 xcopy C:\Documents and Settings\myName\Desktop\trial\source C:\Documents and Settings\myName\Desktop\trial\destination /D /E /C /Q /H /R /Y /K
    • 引用路径:我正在尝试 xcopy "C:\Documents and Settings\myName\Desktop\trial\source" "C:\Documents and Settings\myName\Desktop\trial\destination" /D /E /C /Q /H /R /Y /K
    • AFAIK subversion 将版本信息存储在 .svn 文件夹中。请查看 xcopy 的 /exclude 参数以排除该文件夹中的所有文件。
    【解决方案2】:

    /D:m-d-y 复制在指定日期或之后更改的文件。如果没有给出日期,则只复制源时间比目标时间新的文件。

    所以只需要 /D 和 /Y 参数来回答原问题:

    xcopy <source> <destination> /D /Y
    

    【讨论】:

      猜你喜欢
      • 2015-07-08
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      • 2021-09-24
      • 2012-07-02
      • 1970-01-01
      • 1970-01-01
      • 2012-04-16
      相关资源
      最近更新 更多