pushing Find.find output into an array

J

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.
Any ideas?

Thanks a ton
-Jon
 
S

Stefano Crocco

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
 
R

Robert Klemme

2007/8/3 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top