epitka
epitka

Reputation: 17637

How to recursively delete all SVN files using PowerShell

How would one go about deleting all Subversion files from a directory using PowerShell?

Upvotes: 34

Views: 9816

Answers (4)

Dreamingwolf
Dreamingwolf

Reputation: 11

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

Upvotes: 1

Keith Hill
Keith Hill

Reputation: 201652

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.

Upvotes: 10

stej
stej

Reputation: 29449

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

Upvotes: 43

Sofahamster
Sofahamster

Reputation: 761

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

Upvotes: 5

Related Questions