Ruby scrip to find Dir based on last modified date

Hi
Can someone here please help/guide me how I can implement the following
scenario.

Scenario:

A directory on my Mac has list of Sub-directories, What I need is Ruby
script that finds the Sub Directory that was Last Modified based on the
modified date and then copy that Sub Directory and it is content to my
Different Dir on my Mac.

Appreciate your much needed help

bal

Robert K. wrote in post #960918:

On Fri, Nov 12, 2010 at 6:41 AM, Bal S. [email protected]
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”]

Cheers

robert

Hi Robert
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 ?

thanks

On 11/12/2010 10:03 PM, Bal S. wrote:

irb(main):002:0> Dir["*"].select {|f| test ?d, f}.sort_by {|f|
File.mtime f}
=> [“lib”, “vimfiles”, “ruby”, “a1”, “doc”, “bin”, “desktop”]

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

On Fri, Nov 12, 2010 at 6:41 AM, Bal S. [email protected]
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”]

Cheers

robert