Skip to content

Instantly share code, notes, and snippets.

@joewilliams
Created December 18, 2009 02:06
Show Gist options
  • Save joewilliams/259217 to your computer and use it in GitHub Desktop.
Save joewilliams/259217 to your computer and use it in GitHub Desktop.
dir = "."
search = "someterm"
replace = "replace term"
extension = ".cfg"
files = Dir.new(dir).entries
files.delete(".")
files.delete("..")
files.each do |filename|
full_path = "#{dir}/#{filename}"
if extension.include?(File.extname(full_path))
file = File.open(full_path, 'r')
updated_file = ""
file.each do |line|
updated_file << line.gsub(/#{search}/, replace)
end
file.close
file = File.open(full_path, 'w')
file.write(updated_file)
file.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment