From: Mark Thomas Date: 2008-12-19T04:47:52+09:00 Subject: Re: Show newest file in directory? On Dec 18, 12:36 pm, Mmcolli00 Mom wrote: > If you have a directory full of files, how can you get the newest file > and oldest file from that directory? One way... ages = Dir["C:/New"].map{|f| [f,File.mtime(f)] }.sort_by{|i|i[1]} This gives you a sorted list of [filename,age] pairs. Then you can do this: newest, oldest = ages[0][0], ages[-1][0] Or, if you want it in one fell swoop: newest, oldest = Dir["C:/New"].map{|f| [f,File.mtime(f)] }.sort_by{| i|i[1]}.map{|i| i[0]}.values_at(0,-1) This is known as a "Swartzian Transform" -- Mark.