From: John Carter Date: 2005-07-14T06:39:12+09:00 Subject: Re: How do I reduce the memory usage of a script? On Thu, 14 Jul 2005, Scott Ellsworth wrote: > #!/usr/bin/env ruby > require 'find' > def procpath(f) > if File.file?(f) then > if File.fnmatch("*.m4a",f) then > found = false > data = IO.read(f, 65536*8) > re = /[[:alnum:]_., ]{9,}/ > data.scan(re) do |string| > if (string =~ /QuickTime/) then > filename = File.basename(f) > dirname = File.dirname(f) > # puts "#{string} #{dirname}" > puts "#{string} #{dirname} #{filename}" > found = true > break > end > end > if (!found) then > puts "Unknown #{f}" > end > end > elsif File.directory?(f) && !File.fnmatch(".", f) && > !File.fnmatch("..", f) then > Dir.foreach(f) { |subf| procpath(subf) } Why are you recursing here? Find.find does this stuff for you! > end > end > > Find.find("/Users/work/Music/iTunes/iTunes Music/") do |f| > procpath(f) > end John Carter Phone : (64)(3) 358 6639 Tait Electronics Fax : (64)(3) 359 4632 PO Box 1645 Christchurch Email : john.carter@tait.co.nz New Zealand Carter's Clarification of Murphy's Law. "Things only ever go right so that they may go more spectacularly wrong later." From this principle, all of life and physics may be deduced.