【发布时间】:2019-04-11 22:59:26
【问题描述】:
如果有这段代码
if(Test-Path -Path $OUT)
{
Remove-Item $OUT -Recurse
}
New-Item -ItemType directory -Path $OUT
有时它有效,但有时 New-Item 行会产生 PermissionDenied ItemExistsUnauthorizedAccessError 错误。我认为这意味着之前的 Remove-Item 尚未完全执行,并且无法创建文件夹,因为它仍然存在。
如果我在那里插入睡眠
if(Test-Path -Path $OUT)
{
Remove-Item $OUT -Recurse
Start-Sleep -s 1
}
New-Item -ItemType directory -Path $OUT
那么它总是有效的。 如何强制 Remove-Item 以确保该文件夹被真正删除? 还是我想念别的东西?
【问题讨论】:
标签: powershell filesystems synchronous ntfs