Microsoft
Software
Hardware
Network
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
E-Mail Stuck in Outbox
Unable to access ODBC through a citrix connection
Company trying to sabotage our SEO
How to cat 2 variables variables
How to write a shell script to untar files?
Services Crashing Multiple Times Per Day: wuauserv, bits, browser, trkwks, dmserver, seclogon, lanmanserver, audiosrv, sharedaccess, wzcsvc, and lanmanworkstation
public store problem - database not up to date
Disabled Syskey by mistake
Outlook no longer remembers Active Directory credentials
SSRS FormatDateTime