Robocopy 子目录中不包括根文件的所有内容
Robocopy everything in subdirectory excluding the root files
如何使用 robocopy 不复制根内容?
我已经将根文件存储在其他地方,我只想复制子目录及其内容,而源文件夹仍包含根目录内容。
据我所知,这对于本机 robocopy 开关是不可能的。您将需要使用脚本来枚举子目录并针对它们进行 运行 robocopy。
这是一个示例 PowerShell 命令,它将完成您想要的,将所有内容从 C:\temp\source\ 复制到 c:\temp\target\,不包括 c:[=18 中的文件=]:
get-childitem c:\temp\source\* |?{$_.PsIsContainer} | %{robocopy $_.FullName c:\temp\target$($_.Name) /S}
基础知识归功于 powershell ignore files in root but robocopy folders and their contents。
我没有名声,但 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
如何使用 robocopy 不复制根内容? 我已经将根文件存储在其他地方,我只想复制子目录及其内容,而源文件夹仍包含根目录内容。
据我所知,这对于本机 robocopy 开关是不可能的。您将需要使用脚本来枚举子目录并针对它们进行 运行 robocopy。
这是一个示例 PowerShell 命令,它将完成您想要的,将所有内容从 C:\temp\source\ 复制到 c:\temp\target\,不包括 c:[=18 中的文件=]:
get-childitem c:\temp\source\* |?{$_.PsIsContainer} | %{robocopy $_.FullName c:\temp\target$($_.Name) /S}
基础知识归功于 powershell ignore files in root but robocopy folders and their contents。
我没有名声,但 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