1
我想复制从脚本开始运行和小时前有时间戳的文件。所以我基本上是在模仿robocopy,但是minage和maxage会降到正确的时间而不是几天。到目前为止,我有这个在PowerShell中:如何复制文件和时间戳之间的2倍,并保留目录结构
$now = Get-Date
$previousHour = $now.AddHours(-1)
"Copying files from $previousHour to $now"
function DoCopy ($source, $destination)
{
$fileList = gci $source -Recurse
foreach ($file in $fileList)
{
if($file.LastWriteTime -lt $now -and $file.LastWriteTime -gt $previousHour)
{
#Do the copy
}
}
}
DoCopy "C:\test" "C:\test2"
,但如果我尝试做副本这样的,它会将所有的文件直接到目标文件夹,而不是子文件夹。 enter code here