I had to find some files for processing and wanted to find the latest file by modification date. So here is what I came up with:

    Dir.glob("c:/path/to/files/*.*").sort_by {|f| File.mtime(f) }.reverse[0..7]


grab the entries in the specified directory


##pass the entries into the block for sorting


sort by modification time


reverse the list and show 0 to 7 entries (which comes out to 8 entries)

comments powered by Disqus