Powershell 使用-Recurse和-Force删除项目不会删除所有文件和文件夹
在Powershell中,我有一个脚本,可以清除从TFS检索到的项目文件文件夹 命令很简单:Powershell 使用-Recurse和-Force删除项目不会删除所有文件和文件夹,powershell,Powershell,在Powershell中,我有一个脚本,可以清除从TFS检索到的项目文件文件夹 命令很简单: $deletePath = 'c:\Compile\*' Remove-Item $deletePath -Recurse -Force 在运行之前,c:\Compile中大约有150个文件夹,之后剩下3个文件夹 该脚本生成5个错误 Remove-Item : Cannot remove item C:\Compile\DatabaseObjects: The directory is not emp
$deletePath = 'c:\Compile\*'
Remove-Item $deletePath -Recurse -Force
在运行之前,c:\Compile中大约有150个文件夹,之后剩下3个文件夹
该脚本生成5个错误
Remove-Item : Cannot remove item C:\Compile\DatabaseObjects: The directory is not empty.
Remove-Item : Cannot remove item C:\Compile\IFIFWCHG\obj: The directory is not empty.
Remove-Item : Cannot remove item C:\Compile\IFIFWCHG: The directory is not empty.
Remove-Item : Cannot remove item C:\Compile\PrecompiledWeb\IIS: The directory is not empty.
Remove-Item : Cannot remove item C:\Compile\PrecompiledWeb: The directory is not empty.
我认为由于使用了-Force,它可以处理目录中的文件/文件夹
有趣的是,脚本运行后DatabaseObjects文件夹是空的,因此它似乎在删除文件之前尝试删除文件夹。尝试使用cmdlet检索所有项目,并使用循环对其进行迭代并删除
Get-Childitem 'c:\Compile\' -Recurse | ForEach-Object {
Remove-Item $_.FullName -Force
}
删除nuget
程序包时,此操作可能会失败。如果您通过VS IDE对文件有任何锁定,请确保关闭任何可能阻止此命令成功的应用程序!这回答了你的问题吗?