From: Robert Klemme Date: 2010-01-20T20:46:45+09:00 Subject: Re: help on a script 2010/1/20 Ruby Newbee : > Thanks all. > Under all your helps, I finally get the script to work correctly. > > def myfind(path=".") >    Dir.foreach(path) do |f| >        f = File.join(path,f) > ##        puts f >        if File.file? f >            open(f) do |c| >                puts "#{f}" unless c.read.scan(/ruby/).empty? You just need a single match - not all of them. >            end >        elsif File.directory? f and File.basename(f) != "." and > File.basename(f) != ".." >            myfind(f) >        end >    end > end > > myfind It is easier if you use Find: require 'find' Find.find path do |f| puts f if File.file?(f) && /ruby/ =~ File.read(f) end :-) http://www.ruby-doc.org/stdlib/libdoc/find/rdoc/index.html Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/