【问题标题】:Copy-item copies the folder and changes timestamp (Doesn't preserve timestamp)Copy-item 复制文件夹并更改时间戳(不保留时间戳)
【发布时间】:2020-12-02 06:26:55
【问题描述】:

我目前正在创建 Powershell 脚本以将文件夹复制到远程服务器 我使用 copy-item cmdlet 更改文件夹的时间戳。

有没有办法复制文件夹保留文件夹的时间戳?

提前谢谢你

【问题讨论】:

  • 文件夹的时间戳通常与其中的最新文件相同。所以如果你想保持一个特定的日期,你应该操纵文件夹中最新文件的日期。

标签: powershell powershell-remoting copy-item


【解决方案1】:

当您复制目录时,您只需在不同位置创建具有相同名称的新目录

param(
    [System.IO.DirectoryInfo]$sourecDir = "D:\tmp\001",
    [System.IO.DirectoryInfo]$destDir = "D:\tmp\002"
)

[System.IO.Directory]::CreateDirectory("D:\tmp\002")
$destDir.CreationTime = $sourecDir.CreationTime

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-14
    • 2011-07-20
    • 2016-05-07
    • 2016-06-04
    • 2017-09-20
    • 1970-01-01
    • 2011-05-16
    • 1970-01-01
    相关资源
    最近更新 更多