Created
December 18, 2009 02:06
-
-
Save joewilliams/259217 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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