我需要根据文件的使用期限将文件从一个目录复制到另一位置。我还需要保留目录结构。
该代码仅能复制符合条件的文件,但不能保留目录结构:
$ListDate = Get-Date "12/6/2013 11:08 AM"
$ActiveDate = $ListDate.AddYears(-7)
Get-ChildItem -path "T:\ProductionServices" -recurse | where-object {$_.lastwritetime -le $ActiveDate -and -not $_.psiscontainer} | Copy-item -destination "T:\TECH\CopyOfDeleteFile"
我已经为此进行了一个多星期的努力,并且尝试了我在这里和互联网上看到的所有建议。我只需要一点点努力就可以找出我做错了什么。
这是对robocopy而言比PowerShell更好的情况之一(或者将robocopy与PowerShell一起使用)。尽管使用robocopy,您无法获得最新的分辨率(我认为)
robocopy t:\Productionservices t:\tech\copyofdeletefile /E /MINAGE:20061206
或者,如果您想将其与PowerShell一起使用以进行日期数学计算:
$ListDate = Get-Date "12/6/2013 11:08 AM";
$ActiveDate = get-date $($ListDate.AddYears(-7)) -f "yyyyMMdd";
robocopy t:\Productionservices t:\tech\copyofdeletefile /E /MINAGE:$ActiveDate;
您也可以使用/COPY:DAT /DCOPY:T
开关保留所有属性和时间戳。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句