小编arm*_*enm的帖子

PowerShell Remove-Item不等待

如果有这段代码

if(Test-Path -Path $OUT) 
{ 
    Remove-Item $OUT -Recurse 
}
New-Item -ItemType directory -Path $OUT
Run Code Online (Sandbox Code Playgroud)

有时它可以工作,但有时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
Run Code Online (Sandbox Code Playgroud)

然后它总是可以工作。如何强制Remove-Item以确保文件夹已真正删除?还是我想念其他东西?

filesystems powershell ntfs synchronous

5
推荐指数
2
解决办法
1984
查看次数

标签 统计

filesystems ×1

ntfs ×1

powershell ×1

synchronous ×1