Question : I need a script to delete files older than 3 days in a directory

Hi I need a Ruby script to delete files that are older than 3 days from I guess Time.now. Can someone help me with this? Thanks.

Answer : I need a script to delete files older than 3 days in a directory

Something along this lines will do the work:
#!/usr/bin/ruby
require "rubygems"
require "active_support"
require "fileutils"


if (ARGV.length == 1) then
  testing = true
end


WORK_DIR
old_dir = Dir.pwd
Dir.chdir(WORK_DIR)
Dir["*"].each do
    | file |
    if (File.mtime(file) < Time.now - 3.days) then
      # p File.mtime(dir)
    if (testing) then
      print("Would remove #{file}\n")
      else
       File.unlink(file)
    end
Dir.chdir(old_dir)

This will work find if you have Rails installed.

Regards
Friedrich
Random Solutions  
 
programming4us programming4us