From: Justin Collins Date: 2007-10-14T08:43:19+09:00 Subject: Re: top 10 last played mp3's Robin Wagenaar wrote: > Hello everyone, > > 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. > > I'm sure you can give me some simple hints, or a small push in the right > direction. Thanks in advance. > > > > this is what I have so far: > > require 'find' > require 'date' > > dir = "/share/music" > > Find.find(dir) do |path| > > if File.directory?(path) > next > else > if path.match(".*mp3") != nil > print File.atime(path)," : " > print path,"\n" > end > end > > end > Your original question has been answered already, but just a small note: puts and string interpolation is generally a lot simpler to use for output: puts "#{File.atime(path)} : #{path}" That will also add the "\n" or "\r\n" as appropriate, so you do not need to. -Justin