开发者

How to recursively delete all SVN files using PowerShell

开发者 https://www.devze.com 2022-12-19 02:33 出处:网络
How would one go about deleting all Subversion files from a directory using P开发者_JS百科owerShell?If you really do want to just delete the .svn directories, this could help:

How would one go about deleting all Subversion files from a directory using P开发者_JS百科owerShell?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号