How to remove .svn directories from an application

Posted by Jason, Sun Feb 04 00:40:00 UTC 2007

Whenever I notice the same question coming up a few times in the course of a week, I normally consider it a flag to post something on it here. Then, when it comes up again I can just paste over a URL rather than take the time to explain it again. This is one of those flags. In the past week, there have been three people make their way onto IRC asking how to remove all of the .svn directories out of an application. Some had an interest to build this functionality into their application, others just wanted something from command line. I know it seems like a trivial thing to post, but, I figured I have the space...

If you want to build functionality to remove all of the subversion dot directories into your application, this is one of the many ways you could go about accomplishing it:


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


If however, you are not a rubiest and are just looking for some Unix approach, this should get the job done:


`find . -type d -name .svn -delete`


FYI, the Unix command line version fails unless all of the .svn directories are already empty. The ruby version does not suffer from this limitation. You could always do something like:


find . -type d -name .svn > svnlist.txt && \
rm -rf `cat svnlist.txt` && rm -rf svnlist.txt
To get around it if you don't mind being a bit of a hack..

Filed Under: Hacks | Tags:

Comments

Have your say

A name is required. You may use HTML in your comments.