pushing Find.find output into an array

Discussion in 'Ruby' started by Jon Hawkins, Aug 3, 2007.

  1. Jon Hawkins

    Jon Hawkins Guest

    Im basically wanted to throw the output from a find into an array

    require 'find'
    Dir.chdir('/')
    Find.find("/", "./") {|x| puts x} ---> need to push the results into
    an array with each item being a different element.
    Any ideas?

    Thanks a ton
    -Jon
    --
    Posted via http://www.ruby-forum.com/.
    Jon Hawkins, Aug 3, 2007
    #1
    1. Advertising

  2. Alle venerd=C3=AC 3 agosto 2007, Jon Hawkins ha scritto:
    > Im basically wanted to throw the output from a find into an array
    >
    > require 'find'
    > Dir.chdir('/')
    > Find.find("/", "./") {|x| puts x} ---> need to push the results into
    > an array with each item being a different element.
    > Any ideas?
    >
    > Thanks a ton
    > -Jon


    Is this what you need?

    res =3D []
    =46ind.find('/', './'){|f| res << f}

    Stefano
    Stefano Crocco, Aug 3, 2007
    #2
    1. Advertising

  3. 2007/8/3, Jon Hawkins <>:
    > Im basically wanted to throw the output from a find into an array
    >
    > require 'find'
    > Dir.chdir('/')
    > Find.find("/", "./") {|x| puts x} ---> need to push the results into
    > an array with each item being a different element.


    Why do you traverse the root filesystem twice?

    require 'find'
    require 'enumerator'

    f1 = Find.to_enum:)find, "/").to_a
    f2 = Dir['**/*']

    Note: results may differ.

    Cheers

    robert
    Robert Klemme, Aug 3, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hall
    Replies:
    4
    Views:
    431
  2. =?Utf-8?B?VW1lc2huYXRo?=

    Pushing data into a Control with out Ajax

    =?Utf-8?B?VW1lc2huYXRo?=, Jul 25, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    406
    =?Utf-8?B?VW1lc2huYXRo?=
    Jul 25, 2007
  3. =?Utf-8?B?VW1lc2huYXRo?=

    Pushing data into a Control with out Ajax

    =?Utf-8?B?VW1lc2huYXRo?=, Jul 26, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    359
    =?Utf-8?B?VW1lc2huYXRo?=
    Jul 26, 2007
  4. eagle eyes joe
    Replies:
    3
    Views:
    89
    Florian Gross
    Sep 28, 2004
  5. mosar
    Replies:
    1
    Views:
    94
    Michael Guterl
    Sep 4, 2008
Loading...

Share This Page