为什么`rd /S` 说“目录不为空”?

Bor*_*ard 3 powershell command-line

我正在尝试rd /S在非空目录上执行,有时它工作正常,有时它报告“目录不为空”。为什么我收到这个错误?有没有一种可靠的方法可以删除 Windows 下充满文件和子目录的文件夹?PowerShellRemove-Item也存在这个问题。

小智 6

可能是本地防病毒或索引服务扫描并锁定新复制的文件不被立即删除。

我会编程延迟并在失败时重试。

for (i = 1 to 10 etc...)
{
  try to remove directory
  if directory does not exist, break out of loop
  wait a second
}
if directory still exists, abort!
Run Code Online (Sandbox Code Playgroud)