Reputation: 58120
I have an array of filenames, is there any way to sort these files by modification date?
Upvotes: 7
Views: 7081
Reputation: 370367
You can use the sort_by
method in conjunction with File.mtime
method, which returns the last modification time of the given file.
filenames.sort_by {|filename| File.mtime(filename) }
Upvotes: 16