From: Dave Howell Date: 2006-05-04T08:44:46+09:00 Subject: Re: Searching Files On May 3, 2006, at 8:49, Nathan Olberding wrote: > Michael Greenly wrote: >> require 'find' >> >> search_term = /pear/ >> >> Find.find("./") do |path| >> next unless File.file?(path) >> File.open(path) do |file| >> lineno = 0 >> file.each do |line| >> lineno += 1 >> if line =~ search_term >> puts "#{path}:#{lineno} " + line >> end >> end >> end >> end > > I've played with this and it seems to have the same problem as my > original code: it will only find maybe 10% of the results I expect (so > far only one result in either implementation, no matter the search). That strongly implies that the problem is with your search terms, not your code. Or to put it another way, that what you think is in those files, isn't actually there. For example, if you try to search for something like /this phrase/ in a file that's been saved as UTF-16 and your searching program doesn't know that, then you won't find that phrase, because it doesn't exist. In the file, it would be more like ?t?h?i?s? ?p?h?r?a?s?e where the ?'s represent an ASCII "NUL" character, 00. If you're trying to search Word files, or RTF files, then there's all sorts of stuff that might be stored between the items of your search. So what, exactly, are you trying to search for, and are you positive that it's actually in the files?