Standard IO directory surf

how would i go about surfing a whole directory instead of using a
Dir.glob(*/**)
Basically how would i do it using the Find method. I need to surf the
entire file system and pull up my total number of files that arnt an
actual directory.

Thanks,

-Jon

oh and i also want to pipe the find… find -blah -blah | ./program.rb
— how would i go about doing this?

Jon H. wrote:

how would i go about surfing a whole directory instead of using a
Dir.glob(*/**)
Basically how would i do it using the Find method. I need to surf the
entire file system and pull up my total number of files that arnt an
actual directory.
Three ways (at least) to do this:

1: Using Dir.glob:
file_list = Dir.glob(’**/*’).select{|filename|
File.file?(filename)}

2: Using Find:
file_list = []
Find.find(’/’) {|path| file_list << path if File.file? path}

3: Using /usr/bin/find:
file_list = find . -type f.split

Once you’ve got file_list, you can take file_list.length to get the
number of files. If you want to avoid having an intermediate array, you
could use Find this way:

file_count = 0
Find.find(’/’) {|path| file_count += 1 if File.file? path}

On Aug 9, 2007, at 12:47 PM, Jon H. wrote:

how would i go about surfing a whole directory instead of using a
Dir.glob(*/**)
Basically how would i do it using the Find method. I need to surf the
entire file system and pull up my total number of files that arnt an
actual directory.

http://drawohara.tumblr.com/post/8166787

cheers.

a @ http://drawohara.com/

On Fri, 10 Aug 2007 04:28:21 +0900, Jon H. wrote:

oh and i also want to pipe the find… find -blah -blah | ./program.rb
— how would i go about doing this?

do it without ruby and just use the shell?

find -type f | ./program.rb

2007/8/9, Jon H. [email protected]:

how would i go about surfing a whole directory instead of using a
Dir.glob(*/**)
Basically how would i do it using the Find method. I need to surf the
entire file system and pull up my total number of files that arnt an
actual directory.

non_directory_count = Integer find / -not -type d | wc -l

Of course, the command in backticks also works on a shell prompt - if
you just need that count. (btw, I used Integer to detect situations
where the command does not work and return an improper result (i.e. an
empty string).

Kind regards

robert