Forum: Ruby pushing Find.find output into an array

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
57a778becb5ea951889fa9f0b4e3bd15?d=identicon&s=25 Michael Linfield (macgoober)
on 2007-08-03 02:39
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
C40020a47c6b625af6422b5b1302abaf?d=identicon&s=25 Stefano Crocco (crocco)
on 2007-08-03 08:50
(Received via mailing list)
Alle venerdì 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 = []
Find.find('/', './'){|f| res << f}

Stefano
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2007-08-03 14:02
(Received via mailing list)
2007/8/3, Jon Hawkins <globyy3000@hotmail.com>:
> 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
This topic is locked and can not be replied to.