From: "Andreas S." Date: 2007-10-14T06:48:42+09:00 Subject: Re: top 10 last played mp3's Robin Wagenaar wrote: > My level of ruby-experience has just slightly passed hello-world, I'm > quite new to this programming language; I hope I don't bother all of you > too much by posting my low-level question here. > > I would like to make a program that iterates recursively trough my music > directory, and selects the top-10 of most recently played tracks. > > I try to use File.atime(path) to check if the current file is accessed > recently enough to get into my top-10, but my problem is that I don't > know how to (correctly) compare a date to the return value of > File.atime. File.atime returns a Time object, you can compare it to another Time object, for example: if File.atime(path) > (Time.now - 60*60) # file has been accessed in the last hout end But you can also solve the whole problem much easier: Dir['/share/music/**/*.mp3', '/share/music/*.mp3'].sort_by{|f| File.atime}.reverse[0,10] -- Posted via http://www.ruby-forum.com/.