On Wed, Aug 07, 2002 at 06:08:37AM +0900, Kurt Euler wrote:
> Newbie question: What's the Ruby command to unconditionally delete
> all files in a directory?

I use this:


require 'find'

class Dir
  def Dir.visit(dir = '.', files_first = false, &block)
    if files_first
      paths = []
      Find.find(dir) { |path| paths << path }
      paths.reverse_each {|path| yield path}
    else
      Find.find(dir, &block)
    end
  end

  def Dir.rm_rf(dir)
    Dir.visit(dir, true) do |path|
      if FileTest.directory?(path)
        Dir.unlink(path)
      else
        File.unlink(path)
      end
    end
  end
end



Massimiliano