What's an idiomatic way to find the most recently modified file within a directory?
Dir.glob("*").max_by {|f| File.mtime(f)}
Dir["*"].sort { |a,b| File.mtime(a) <=> File.mtime(b) }.last
This is not recursive.
I'm not sure if there really is an idiom for this. I would do
Dir["*"].sort_by { |file_name| File.stat(file_name).mtime }
Seeing how three people gave more or less the same answer at the same time. This must be it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With