From: Robert Klemme Date: 2008-01-22T02:20:56+09:00 Subject: Re: Timeout error using Find module 2008/1/21, Mike -- : > I'm not sure about the network drive situation...the script does seem to > timeout and terminate once it reaches the folder '/net/'. I tried > navigating into this folder and discovered two entries - 'broadcasthost' > and 'localhost', both of which result in a timeout in the terminal > window when I try to access them. I know this isn't really related to > Ruby, but again any info people might have would be very appreciated. Yeah, some Mac wizzard should be able to answer you this. Since I'm not a Mac user... :-) > Again, Robert, thanks for the info about not needing to chomp the > returned string from the user when using it with the Find module. Where exactly did I say this? I believe I did not and if, it would be wrong: $ ruby -e 'p gets' foo "foo\n" > Robert Klemme wrote: > > On 19.01.2008 22:53, Mike -- wrote: > > Why do you prune here? What this basically means is that traversal will > > stop on every directory that contains at least one file name that does > > not match your regexp. Is this really what you want? > > Yea, I think I know what you mean. No need for it really. I was playing > with something I saw on another web page whereby the programmer was > telling the Find script not to bother looking into Mac folders that > began with a '.', and I guess I just didn't think to remove it. Ah, ok. > > Is this really the exact code that produced the error you present above? > > I ask because you do not print out the exception itself but rather > > the fixed string "Timeout error :S". > > Yep, that's the exact code I was using at the time of posting. I haven't > gotten round to finding out how to print out the details of the > exception so I just got it to tell me if an error occurred. I figured Hm, strange. Maybe the timeout is caught somewhere in #find and printed to $stderr before another exception is thrown (if there is). Btw, if you want to access the error you can do rescue SystemCallError => e puts e # or whatever, see docs > > This is how I would probably do it - assuming you want to find all files > > and directories where the basename matches the given regexp. > > > > require 'find' > > dir = ARGV.shift or raise "Need a directory name" > > rx = Regexp.new((ARGV.shift or raise "Need a regexp"), > > Regexp::IGNORECASE) > > > > Find.find dir do |f| > > if rx =~ File.basename(f) > > print File.directory?(f) ? "Dir : " : "File: ", f, "\n" > > end > > end > > I hate you. You've managed to take my 30something lines and make > reproduce it in 10. Well, not exactly. For one, the printout will be different. Btw, if you do not need full regular expression support you can even make it a near one liner: puts Dir["#{base}/**/#{glob}"] > Thanks, good for me to see this sort of thing in > action so I can learn from it. Although I'm not running my code from the > command line so I wouldn't use the ARGV commands, but again good to know > about them. I do appreciate the help, I'm still at novice level of > programming so it's always good to see "best practice" code. You're welcome! You'll have plenty of fun with Ruby, I'm sure. > I reproduced the same code in Perl to perform the same search function > which didn't produce the same search error, so I guess that Perl does > not have an issue with the network mounts? Maybe Perl does some optimization (i.e. not reading those directories on a Mac) or simply ignores the timeout. > Also, the Perl code seemed to > return significantly more results from the search when performed on my > Vista machine (used alongside the Ruby code), which seemed odd to me? > Not a huge issue, but still... Are you sure both machines contain the same amount of files? Kind regards robert -- use.inject do |as, often| as.you_can - without end