在使用Remove-Item递归删除空文件夹的PS脚本中,我得到了一些空文件夹的异常“拒绝访问云文件”。
y53ybaqx1#
即使我没有安装OneDrive,本文https://evotec.xyz/remove-item-access-to-the-cloud-file-is-denied-while-deleting-files-from-onedrive/中的解决方案$dir.Delete($true)也可以工作
$directoriesToDelete = Get-ChildItem -Path $pathToPictures -Recurse -Directory foreach ($directoryToDelete in $directoriesToDelete) { $pathToDirectory = $directoryToDelete.FullName if ((Get-ChildItem $pathToDirectory | Measure-Object).Count -eq 0) { try { Remove-Item $pathToDirectory -Force Add-LogEntry -PathToLog $logFile -LogEntry "$pathToDirectory deleted" } catch { if ($_.Exception.Message -eq 'Access to the cloud file is denied') { $dir = Get-Item -LiteralPath $pathToDirectory try { $dir.Delete($true) } catch { Add-LogEntry -PathToLog $logFile -LogEntry "Error deleting '$pathToDirectory' (using dir.Delete): $_" } } else { Add-LogEntry -PathToLog $logFile -LogEntry "Error deleting '$pathToDirectory': $_" } } } }
0yg35tkg2#
我得到了这个错误的Windows.old文件夹有OneDrive子文件夹.什么工作是运行chkdsk c: /r /f
chkdsk c: /r /f
2条答案
按热度按时间y53ybaqx1#
即使我没有安装OneDrive,本文https://evotec.xyz/remove-item-access-to-the-cloud-file-is-denied-while-deleting-files-from-onedrive/中的解决方案$dir.Delete($true)也可以工作
0yg35tkg2#
我得到了这个错误的Windows.old文件夹有OneDrive子文件夹.什么工作是运行
chkdsk c: /r /f