From: Robert Klemme Date: 2010-11-13T19:10:18+09:00 Subject: Re: Ruby scrip to find Dir based on last modified date On 11/12/2010 10:03 PM, Bal Sidhu wrote: > Robert Klemme wrote in post #960918: >> On Fri, Nov 12, 2010 at 6:41 AM, Bal Sidhu >> wrote: >>> >>> Appreciate your much needed help >> >> This should get you started: >> >> irb(main):001:0> Dir["*"].select {|f| test ?d, f} >> => ["a1", "bin", "desktop", "doc", "lib", "ruby", "vimfiles"] >> irb(main):002:0> Dir["*"].select {|f| test ?d, f}.sort_by {|f| >> File.mtime f} >> => ["lib", "vimfiles", "ruby", "a1", "doc", "bin", "desktop"] > Thanks for you reply, much appreciated, above command work fine, seems > it need further change, This is what I am trying to achieve, > > e.g. Below is list of Directories exists in my home Dir, say my home Dir > is /home/myhome/ > > drwxr-xr-x 4 testuser staff 136 Oct 19 15:27 .argouml > drwxr-xr-x 7 testuser staff 238 Aug 25 15:02 .yed3 > drwxr-xr-x 23 testuser staff 782 Aug 12 13:23 enli.x > > using ruby script I lik to find Dir with latest time stamp and then copy > the that Dir to diff Dir e.g. /usr/bin/ > > I google to see if their is ruby method exist to find scan the Dir then > find the one with latest time stamp, i couln't find anything, > > any thoughts ? Use #max_by. And look into FileUtils for the copying. robert