Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 复制项复制文件夹并更改时间戳(不保留时间戳)_Powershell_Powershell Remoting_Copy Item - Fatal编程技术网

Powershell 复制项复制文件夹并更改时间戳(不保留时间戳)

Powershell 复制项复制文件夹并更改时间戳(不保留时间戳),powershell,powershell-remoting,copy-item,Powershell,Powershell Remoting,Copy Item,我当前正在创建Powershell脚本以将文件夹复制到远程服务器 我使用copy item cmdlet更改文件夹的时间戳 有没有办法复制文件夹并保留文件夹的时间戳 提前感谢复制目录时,只需在不同位置创建同名的新目录即可 param( [System.IO.DirectoryInfo]$sourecDir = "D:\tmp\001", [System.IO.DirectoryInfo]$destDir = "D:\tmp\002" )

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

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


提前感谢

复制目录时,只需在不同位置创建同名的新目录即可

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

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