From: Michael Fellinger Date: 2011-01-09T03:39:32+09:00 Subject: Re: file list sorted by creation date On Sat, Jan 8, 2011 at 6:45 PM, zuerrong wrote: > Or use a Swatz* Transform which is used by sort_by inherently: > > Dir.entries(".").map{|c| [c,File.stat(c).ctime]}.sort{|a,b| > a[1]<=>b[1]}.map{|d| d[0]} > > * Swatz is a Perl hacker whose full name is Randal Swatz (hope me > remember that correctly). You mean Randal Schwartz and his Schwartzian transform: https://secure.wikimedia.org/wikipedia/en/wiki/Schwartzian_transform As you said, sort_by implements that already, so it's faster to use it instead directly. > > 2011/1/8 zuerrong : >> 2011/1/8 Rajarshi Chakravarty : >>> Hi, >>> I need to get a list of all files in a directory sorted by their >>> date/time of creation. >> >> sort_by it: >> >> Dir.entries(".").sort_by{|c| File.stat(c).ctime} -- Michael Fellinger CTO, The Rubyists, LLC