Delete folder older than a certain time
def delete_older(dir, time)
save = Dir.getwd
Dir.chdir(dir)
Dir.foreach(".") do |entry|
# We're not handling directories here
next if File.stat(entry).directory?
# Use the modification time
if File.mtime(entry) < time
File.unlink(entry)
end
end
Dir.chdir(save)
end
delete_older("/tmp",Time.local(2001,3,29,18,38,0))
Related examples in the same category