如何使用PowerShell从目录中删除所有Subversion文件?
如何使用PowerShell从目录中删除所有Subversion文件?
如果你确实只想删除 .svn 目录,可以尝试以下方法:
gci c:\yourdirectory -include .svn -Recurse -Force |
Remove-Item -Recurse -Force
编辑:
在gci
命令中添加了-Force
参数以列出隐藏的目录并缩短代码。
如果您需要避免删除具有 .svn 扩展名的文件,则应使用 ?
过滤项目。Keith是正确的。
Get-ChildItem dir -recurse -exclude ..
是一样的情况。-exclude
(如果我记得正确,还有 -include
)与 -recurse
不兼容。 - stej假设您不想删除任何可能也带有 .svn 扩展名的文件:
Get-ChildItem $path -r -include .svn -Force | Where {$_.PSIsContainer} |
Remove-Item -r -force
微软已回应下面评论中开放的建议,因为在PowerShell V3中你可以使用-directory
来取代额外的(非常慢的)管道符Where {$_.PSIsContainer}
:
gci $path -r -include .svn -force -directory | Remove-Item -r -force
你可以从 Windows Management Framework 3.0下载PowerShell v3用于Windows 7。
Where {$_.PSIsContainer}
,而只需要执行 gci . -r -containerOnly
。我已经将我的 Get-ChildItem 代理成这种方式工作,但我不能保证其他人也有这样的设置。 :-( - Keith Hill如果你想删除所有文件名中包含特定字符串的文件,那么stej的回答是正确的。在这种情况下,你应该使用:
gci "your_path" -include \*"specific_string"\* -Recurse -Force | Remove-Item -Recurse -Force
your_path
包含空格或特殊字符时,才需要加引号。specific_string
需要加引号以确保识别两个通配符,特别是如果字符串包含如()
这样的字符。