Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Recursively remove .svn directories (ruby script) (See related posts)

This snippet traverses a directory tree and removes .svn directories.

require 'find'
require 'fileutils'
Find.find('./') do |path|
  if File.basename(path) == '.svn'
    FileUtils.remove_dir(path, true)
    Find.prune
  end
end

Comments on this post

nickstenning posts on Oct 07, 2006 at 12:35
Erm...

`find . -type d -name .svn -delete`
SnapShot posts on Nov 01, 2006 at 01:38
BTW, unix command line version fails unless all of the .svn directories are already empty. The ruby version does not have this limitation.
nedric posts on Nov 22, 2006 at 17:13
You probably have another reason for wanting to delete .svn dirs, but just in case: you should look at the svn 'export' command. You can use it on a url or working copy to cleanly extract just the contents without the svn metadata.
Jeff-O-Noah posts on Feb 21, 2007 at 01:29
How about best of both worlds? Use the find command above to provide a list of directories to delete within a much simpler shell script:
#!/bin/sh
for FILE in `find . -type d -name .svn`;
do
echo $FILE
rm -r $FILE
done
incognito posts on Mar 05, 2007 at 05:55

find . -type d -name .svn | xargs rm -rf

You need to create an account or log in to post comments to this site.


Related Posts