[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

standard IO directory surf

Michael Linfield

8/9/2007 6:48:00 PM

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
--
Posted via http://www.ruby-....

5 Answers

Michael Linfield

8/9/2007 7:28:00 PM

0

oh and i also want to pipe the find.... find -blah -blah | ./program.rb
--- how would i go about doing this?
--
Posted via http://www.ruby-....

Alex Young

8/9/2007 7:41:00 PM

0

Jon Hawkins 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}


--
Alex

ara.t.howard

8/9/2007 7:53:00 PM

0


On Aug 9, 2007, at 12:47 PM, Jon Hawkins 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/po...

cheers.

a @ http://draw...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Ken Bloom

8/10/2007 4:38:00 AM

0

On Fri, 10 Aug 2007 04:28:21 +0900, Jon Hawkins 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


--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...

Robert Klemme

8/10/2007 8:20:00 AM

0

2007/8/9, Jon Hawkins <globyy3000@hotmail.com>:
> 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