I needed to erase SVN folders from a directory. Ironically, I needed to do this so that I could put them back, in a cleaner format, into the repository.
Here is the script that I wrote in ruby to do this:
#! usr/bin/env ruby
def delete_dir(dir_name)
d = Dir.new(dir_name)
d.each{ |file|
if !(file == "." || file == "..") then
if File.directory?(file) then
delete_dir(file)
else
File.delete(file)
end
end
}
Dir.delete(dir_name)
end
def clean_svn(dir_name)
d = Dir.new(dir_name)
d.each {|file_name|
if !(file_name == "." || file_name == "..") then
if file_name == ".svn" then
delete_dir(file_name)
end
if File.directory?(file_name) then
clean_svn(file)
end
end
}
end
file = ARGV[0]
clean_svn(file)I have two comments on the script. First, there seems to be a nice FileUtils method that does delete a folder recursively. I learned about it after I finished writing this, so delete_dir is unnecessary.
Second, the limitation of this script is that it is using recursion, and that stack must be shallow, since ruby is not an optimized functional language. So if there are too many directories within directories, it will choke at some point.
But for my purposes, this worked well.