Forum: Ruby Delete and compress logfiles

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B8c0fa903537801d9268fc77b98e0039?d=identicon&s=25 Ruby Amateur (rubyamateur)
on 2017-03-29 09:03
Hello, together
Since last month I work with Ruby.
I realised that I leave in the work often log files which are older than
1 month.
Now I want to delete them, however, a ruby script would be more sensible
there.

I know, I can do that in shell, but I want it in ruby.

Can someone send me a example script who does that?
Greetings
rubyamateur
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2017-03-29 20:08
Ruby Amateur wrote in post #1185726:
> Hello, together
> Since last month I work with Ruby.
> I realised that I leave in the work often log files which are older than
> 1 month.
> Now I want to delete them, however, a ruby script would be more sensible
> there.



last_month= Date.today << 1
Dir.glob("*.log").select {|f|
   File.mtime(f).to_date < last_month
}.each {|f|
  File.delete(f)
}
This topic is locked and can not be replied to.