PowerShell每隔1秒, 检查一下桌面上的abc文件夹及创建时间遇到的问题
我想实现每隔1秒, 检查一下桌面上的abc文件夹是否存在, 当存在时, 检查它的创建时间,当创建时间和当前时间相差20秒时,回显OK但是第一句就卡壳了, 因为get-item会报错, 求高手指引, 提前感谢[code]$Fo = get-item "$HOME\Desktop\abc"
while ($true)
{
$ts = ((Get-Date) - $Fo.CreationTime).TotalSeconds
if ((Test-Path $Fo) -and ($ts -lt 20)) { "OK" }
Sleep 1
$i++
}[/code] 把get-item去掉呢[code]$Fo = "$HOME\Desktop\abc"
while ($true)
{
if (Test-Path $Fo) {
$ts = ((Get-Date) - (get-item $Fo).CreationTime).TotalSeconds
if($ts -gt 20){ "OK" }
}
Sleep 1
$i++
}[/code]
页:
[1]