def delete_all(dir)
Dir.foreach(dir) do |e|
# Don't bother with . and ..
next if [".",".."].include? e
fullname = dir + File::Separator + e if FileTest::directory?(fullname)
delete_all(fullname) else
File.delete(fullname) end end
Dir.delete(dir) end
delete_all("dir1") # Remove dir1 and everything under it!