Hey everyone,

I'm relatively new to Ruby, and am loving it! However, I'm getting some
trouble trying to implement a simple search application. The idea is to
search a directory (specified by the user) for a given reg. expression
in the filename (again specified by the user). Easy, really.

This works fine for the most part, but if I choose to search from the
root directory, I get a operation timeout error like so:

/usr/local/lib/ruby/1.8/find.rb:43:in `open': Operation timed out -
/net/broadcasthost (Errno::ETIMEDOUT)
  from /usr/local/lib/ruby/1.8/find.rb:43:in `find'
  from /usr/local/lib/ruby/1.8/find.rb:38:in `catch'
  from /usr/local/lib/ruby/1.8/find.rb:38:in `find'
  from ruby_find3.rb:10

I'm a little confused as to why it would timeout if it's simply
traversing the local directory tree? I would be grateful if anyone would
be able to give any assistance - I'm sure it's probably a simple fix!

Apologies if something like this has been discussed already...I have had
a look at some forum posts and have only been able to find
server-related timeout threads so far. I did learn about rescuing these
timeout errors from some threads, which I had a stab at implementing
briefly at the end.

Here's my code:

==========================
require 'find'
path = gets.chomp
search1 = gets.chomp
search_exp = Regexp.new(search1, Regexp::IGNORECASE)

puts "<<-- Beginning Search -->>"

begin
  Find.find(path) do |p|
    if FileTest.directory?(p)
      if File.basename(p) =~ search_exp
        puts "Dir: " + File.basename(p)

      # Ignore directories beginning with "."
      elsif File.basename(p)[0] == ?.
        Find.prune
      end
    end

    if FileTest.file?(p)
      if (File.basename(p) =~ search_exp)
        puts File.basename(p) + " : " + File.expand_path(p)
      else
        Find.prune
      end
    end
  end
rescue SystemCallError
  puts "Timeout error :S"
end

puts "<<-- End of Search -->"
-- 
Posted via http://www.ruby-forum.com/.