简体   繁体   中英

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:

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.

Keith is right that it you need to avoid deleting files with .svn extension, you should filter the items using ? .

Assuming you don't want to delete any files that might also have .svn extension:

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! As of PowerShell V3 you can do away with the extra (very slow) pipe to Where {$_.PSIsContainer} and use -directory instead:

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 .

How about using SVN Export to get a clean checkout without .svn directories?

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. 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.

specific_string requires quotes to make sure both wildcards are recognized, especially if the string includes characters such as () .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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