简体   繁体   English

如何使用PowerShell递归删除所有SVN文件

[英]How to recursively delete all SVN files using PowerShell

如何使用PowerShell从目录中删除所有Subversion文件?

If you really do want to just delete the .svn directories, this could help: 如果您确实只想删除.svn目录,这可能会有所帮助:

gci c:\yourdirectory -include .svn -Recurse -Force | 
   Remove-Item -Recurse -Force

Edit: Added -Force param to gci to list hidden directories and shortened the code. 编辑:向gci添加了-Force参数以列出隐藏的目录并缩短了代码。

Keith is right that it you need to avoid deleting files with .svn extension, you should filter the items using ? Keith是正确的,它需要避免删除扩展名为.svn的文件,您应该使用?过滤项目? .

Assuming you don't want to delete any files that might also have .svn extension: 假设您不想删除任何可能也具有.svn扩展名的文件:

Get-ChildItem $path -r -include .svn -Force | Where {$_.PSIsContainer} |
    Remove-Item -r -force

Microsoft has responded to the suggestion in the comments below that Keith opened on MS Connect! Microsoft在下面的评论中回应了Keith在MS Connect上打开的建议中的建议! As of PowerShell V3 you can do away with the extra (very slow) pipe to Where {$_.PSIsContainer} and use -directory instead: 从PowerShell V3开始,您Where {$_.PSIsContainer}通往Where {$_.PSIsContainer}的多余(非常慢)管道,而使用-directory代替:

gci $path -r -include .svn -force -directory | Remove-Item -r -force

PowerShell v3 can be downloaded for Windows 7 at Windows Management Framework 3.0 . 可以从Windows Management Framework 3.0下载Windows 7的PowerShell v3。

How about using SVN Export to get a clean checkout without .svn directories? 在没有.svn目录的情况下,如何使用SVN导出获得干净的结帐呢?

Edit 编辑

You might want to look at the answer here: 您可能要在这里查看答案:

Command line to delete matching files and directories recursively 命令行以递归方式删除匹配的文件和目录

The answer by stej is correct unless you want to delete all file with a specific string in their name. 除非您要删除名称中带有特定字符串的所有文件,否则stej的答案是正确的。 In that case, you should use: 在这种情况下,您应该使用:

gci "your_path" -include \*"specific_string"\* -Recurse -Force | Remove-Item -Recurse -Force

Notes: 笔记:
your_path only requires quotes if it contains spaces or special characters. your_path仅在包含空格或特殊字符的your_path才需要使用引号。

specific_string requires quotes to make sure both wildcards are recognized, especially if the string includes characters such as () . specific_string需要用引号引起来,以确保两个通配符都能被识别,尤其是当字符串包含()等字符时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM