[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

pushing Find.find output into an array

Michael Linfield

8/3/2007 12:40:00 AM

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-....

2 Answers

Stefano Crocco

8/3/2007 6:49:00 AM

0

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

Robert Klemme

8/3/2007 12:02:00 PM

0

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