【问题标题】:Powershell file copy with directory structure具有目录结构的 Powershell 文件副本
【发布时间】:2015-09-14 02:22:22
【问题描述】:

我需要将在一定时间范围内修改的文件连同文件夹结构一起复制到目标目录。我正在使用下面的 powershell 脚本

PS C:\2015-06-27\tfs> get-childitem -recurse | where-object {$_.lastwritetime -gt '06-27-15 01:00' -AND $_.lastwritetime -LT
'06-27-15 11:59' -AND ! $_.PSIsContainer} | Copy-Item -destination c:\test -container - recurse

这会复制文件但不保留源目录结构。如何在各自的目录中复制和创建文件?

【问题讨论】:

    标签: powershell


    【解决方案1】:

    您的问题似乎出在:

    -AND ! $_.PSIsContainer} 
    

    由于您不是以容器为目标,因此您将无法保持所需的文件夹结构。

    get-childitem -recurse | where-object {$_.lastwritetime -gt '06-27-15 01:00' -AND $_.lastwritetime -LT '06-27-15 11:59'} | Copy-Item -destination c:\test -recurse
    

    对我来说很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      • 2017-05-19
      • 1970-01-01
      • 2011-08-10
      • 2014-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多