Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   pushing Find.find output into an array (http://www.velocityreviews.com/forums/t842977-pushing-find-find-output-into-an-array.html)

Jon Hawkins 08-03-2007 12:39 AM

pushing Find.find output into an array
 
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/.


Stefano Crocco 08-03-2007 06:49 AM

Re: pushing Find.find output into an array
 
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


Robert Klemme 08-03-2007 12:02 PM

Re: pushing Find.find output into an array
 
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



All times are GMT. The time now is 04:51 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.