我想将一些文件或文件文件夹从一个文件服务器复制到另一个文件服务器。但是,我想保留原始时间戳和文件属性,以便新复制的文件具有与原始文件相同的时间戳。提前感谢任何答案。
最佳答案
这是一个 powershell 函数,可以满足您的要求......它绝对没有进行健全性检查,所以请注意空客......
function Copy-FileWithTimestamp {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true,Position=0)][string]$Path,
[Parameter(Mandatory=$true,Position=1)][string]$Destination
)
$origLastWriteTime = ( Get-ChildItem $Path ).LastWriteTime
Copy-Item -Path $Path -Destination $Destination
(Get-ChildItem $Destination).LastWriteTime = $origLastWriteTime
}
运行加载后,您可以执行以下操作:
Copy-FileWithTimestamp foo bar
(您也可以将其命名为更短的名称,但使用选项卡完成,没什么大不了的......)
关于powershell - 如何使用powershell复制文件并保留原始时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21593625/