--nextPart1463448.0sYXGqbxM8 Content-Type: text/plain; charset tf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Quoth Andreas 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] Or, if it's deeper than two levels: require 'find' Find.find("/share/music/").sort_by { |f| f.atime }.reverse[0...10] I'm glad you (the OP) are interested in learning more about ruby. Regards, -- Konrad Meyer <konrad / tylerc.org> http://konrad.sobertillnoon.com/ --nextPart1463448.0sYXGqbxM8 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBHEU9vCHB0oCiR2cwRAkCNAKC2vO8oIgkHPzGcE61doMDxmNe0FgCg0J3F 4JW3gQn+01oF69LPuv53sw4 Mx -----END PGP SIGNATURE----- --nextPart1463448.0sYXGqbxM8--