From: Alex Young Date: 2007-08-10T04:41:17+09:00 Subject: Re: standard IO directory surf 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