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.
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:
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.
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama
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
···
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.
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?
--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/