Archive for December, 2009

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" [...]

December 1, 2009 • Posted in: Uncategorized • Comments Closed