Depending on your actual problem, App::Ack might solve it for you. It can traverse directories recursively, search for patterns and strings, and comes with lots of optional bells and whistles.
Comment on Re: searching several files for a string at one time