Ruby: Find ini files containing an entry

Ruby’s always good with the “find”:

require 'find'
 
Find.find(".") do |path|
  Find.prune if path =~ /\.svn$/
  Find.prune if path =~ /XPay$/i
  next unless path =~ /\.ini$/i
  File.open(path,'r') do |f|
    f.each_line do |l|
      next unless l =~ /^\s*dasserver\.exe\s*=\s*(?:[0-9]+\.){3}([0-9]+)\s*$/
      print "#{path} (2.0.2.#{$1})\n" if $1.to_i >= 1885
    end
  end
end
Posted on December 1, 2009 at 9:31 am by Jason Felice · Permalink
In: Uncategorized