From: "Andreas S." Date: 2007-10-14T20:03:46+09:00 Subject: Re: top 10 last played mp3's Brian Adkins wrote: > On Oct 13, 8:35 pm, "Andreas S." > wrote: >> Konrad Meyer wrote: >> > Quoth Andreas S.: >> >> > know how to (correctly) compare a date to the return value of >> >> >> Dir['/share/music/**/*.mp3', '/share/music/*.mp3'].sort_by{|f| >> >> File.atime}.reverse[0,10] >> >> > Or, if it's deeper than two levels: >> >> '**' takes care of that. > > Ah, you're right! I missed that also (even though the ** line is > highlighted in the pickaxe now that I bother to read Dir#glob :) ). > > Before reading your explanation, I put the following together. It > might be a little friendlier for handling multiple extensions I glob can do that easier, too: Dir['/share/music/**/*.{mp3,m4p}'].sort_by{|f| File.atime f}.reverse[0,10] I'd be careful with all these optimizations you are suggesting. By far the slowest part is the recursive traversal of the directory, and you can't speed that up. Array#reverse is in a completely different league and not worth optimizing if you have to sacrifice readability. The File.atime calls are pretty fast, too (100.000 per second on my old powerbook). -- Posted via http://www.ruby-forum.com/.