gpt4 book ai didi

powershell - 无法删除项目。该目录不为空

转载 作者:行者123 更新时间:2023-12-02 18:29:33 26 4
gpt4 key购买 nike

我正在尝试删除包含子文件夹/文件的文件夹。

Remove-Item -Force -Recurse -Path $directoryPath

我收到错误无法删除项目。该目录不为空。

我的PowershellScript.ps1具有executionPolicy unrestricted。我尝试使用当前登录用户删除的根文件夹对此文件夹具有完全权限

在我的本地电脑上,代码可以运行,但在我的 Windows Server 2012 R2 上不行。

最佳答案

您可以尝试以下方法:

Remove-Item -Force -Recurse -Path "$directoryPath\*"

请注意,在 Remove-Item 中将 -Recurse 参数与 -Include 一起使用时,它可能不可靠。因此,最好首先使用 Get-ChildItem 递归文件,然后通过管道传输到 Remove-Item。如果您删除大型文件夹结构,这也可能会有所帮助。

Get-ChildItem $directoryPath -Recurse | Remove-Item -Force   

关于powershell - 无法删除项目。该目录不为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38141528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com