【问题标题】:Robocopy everything in subdirectory excluding the root filesRobocopy 子目录中的所有内容,不包括根文件
【发布时间】:2016-11-16 16:08:35
【问题描述】:

如何使用 robocopy 不复制根目录? 我已经在其他地方存储了根文件,我只想复制子目录及其内容,而源文件夹仍包含根目录内容。

【问题讨论】:

    标签: directory copy robocopy


    【解决方案1】:

    我没有名气,但 Hinkle 先生给出的答案解决了 2 天的努力和搜索。我的挑战是移动超过 1 小时的文件。 powershell 和 robocopy 的这种组合似乎有效。下面是我的最终代码。

    # Clear screen
    cls
    # Disconnect the drive if it exist - don't know where it is pointing to
    If (Test-path p:) {
    net use p: /delete
    }
    #Map the destination
    net use p: \\server\dir1\dir2\dir3 password /USER:domain\user /P:no
    
    get-childitem -path 'D:\dir1\dir2\' |
        where-object {$_.LastWriteTime -lt (get-date).Addhours(-1)} |
        ?{$_.PsIsContainer} |
        %{robocopy $_.FullName p:\$($_.Name) /S /MOVE /r:3 /W:1}
    
    net use p: /delete
    

    【讨论】:

      【解决方案2】:

      据我所知,本机 robocopy 开关无法做到这一点。您将需要使用脚本来枚举子目录并针对它们运行 robocopy。

      这是一个示例 PowerShell 命令,它将完成您想要的操作,将 C:\temp\source\ 中的所有内容复制到 c:\temp\target\,不包括 c:\temp\source 中的文件:

      get-childitem c:\temp\source\* |?{$_.PsIsContainer} | %{robocopy $_.FullName c:\temp\target\$($_.Name) /S}
      

      感谢powershell ignore files in root but robocopy folders and their contents 了解此基础知识。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-08-23
        • 1970-01-01
        • 2023-01-04
        • 1970-01-01
        • 1970-01-01
        • 2022-01-05
        • 1970-01-01
        相关资源
        最近更新 更多