我编写了一个 PowerShell 脚本,它完全正常工作。唯一的挑战是子文件夹中的文件未能移动到目标文件夹。
get-childitem -Path "\\servername\location" |
where-object {$_.LastWriteTime -lt (get-date).AddDays(-31)} |
move-item -destination "C:\Dumps"
我无法进一步定制这个脚本。
我编写了一个 PowerShell 脚本,它完全正常工作。唯一的挑战是子文件夹中的文件未能移动到目标文件夹。
get-childitem -Path "\\servername\location" |
where-object {$_.LastWriteTime -lt (get-date).AddDays(-31)} |
move-item -destination "C:\Dumps"
我无法进一步定制这个脚本。
不要浪费时间试图在PowerShell中重新发明robocopy
。
robocopy \\servername\location C:\Dumps /e /mov /minage:31
简化上述命令为:
robocopy A:\ B:\ /MIR /minage:31
/s
递归到子文件夹。使用/e
(而不是/s
)也包括空的子文件夹。你所说的“另一个位置”是什么意思?您是否不想保留文件夹结构?在这种情况下,您可以坚持使用PowerShell(带有-Recursive
选项,就像 @Musaab提到的那样)。但是,这种方法会使您面临由于覆盖文件而导致数据丢失的风险。 - Ansgar Wiechers