【问题标题】:How to use xcopy to only copy files if they are newer?如果文件较新,如何使用 xcopy 仅复制文件?
【发布时间】:2011-07-13 20:23:01
【问题描述】:

我在 Visual Studio 解决方案中有许多 Web 应用程序。

都有相同的后期构建命令:

xcopy "$(TargetDir)*.dll" "D:\Project\bin" /i /d /y

避免用旧文件替换新文件会很有用(例如,有人可能会不小心添加对旧版本 DLL 的引用)。

如何使用 xcopy 仅将旧文件替换为 Visual Studio 生成的较新的 DLL 文件

【问题讨论】:

标签: visual-studio xcopy post-build-event


【解决方案1】:

在命令行输入“help xcopy”:

/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.

所以您已经在使用 xcopy 仅用新文件替换旧文件。如果这没有发生,您可能需要交换 /i/d 开关的位置。

【讨论】:

    【解决方案2】:

    用户按照命令将所有新的和修改的文件从源复制到目标

    xcopy c:\source d:\destination /D /I /E /Y

    /D 检查是否有任何修改过的文件
    /I 如果目标不存在并且复制多个文件,则假定目标必须是一个目录。
    /E 复制目录和子目录
    /Y 禁止任何覆盖提示。

    【讨论】:

      【解决方案3】:

      未测试,但我对这类任务使用了类似的命令脚本。

      set DIR_DEST=D:\Project\bin
      pushd "$(TargetDir)"
      
      ::
      :: Move Files matching pattern and delete them
      ::
      for %%g in (*.dll) do (xcopy "%%g" "%DIR_DEST%" /D /Y & del "%%g")
      
      ::
      :: Move Files matching pattern
      ::
      :: for %%g in (*.dll) do (xcopy "%%g" "%DIR_DEST%" /D /Y )
      
      popd
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-10-22
        • 1970-01-01
        • 1970-01-01
        • 2013-01-05
        • 1970-01-01
        • 2023-03-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多