From: Glen Date: 2006-02-19T12:23:29+09:00 Subject: Re: Removing files in directtories I wrote the following empty method as an extension to the builtin Dir class. It iterates through a directory deleting all files and directories, leaving the top level directory untouched. class Dir def empty() self.each { |f| if f !~ /^(\.{1,2})$/ file = File.join(self.path, f) if File.stat(file).file? File.delete(file) rescue nil; elsif File.stat(file).directory? d = Dir.new(file) d.empty() Dir.delete(file) rescue nil; end end } end end