Skip to content

Instantly share code, notes, and snippets.

@skatkov
Created June 22, 2012 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skatkov/2972282 to your computer and use it in GitHub Desktop.
Save skatkov/2972282 to your computer and use it in GitHub Desktop.
change loads of text files in directory
#!/usr/bin/env ruby
folder = "Products_HTML/"
new_folder = "fixed_HTML/"
fileForChange = []
def changeFile(file_list, f, n)
Dir.mkdir(n)
file_list.each do |file_name|
text = File.read(f + file_name)
File.open(n + file_name, "w") {|file| file.puts text.gsub(/<a href=/, "<a style='color:blue' href=")}
end
end
#find files
Dir.foreach(folder) {|x| fileForChange << x if File.file?(folder+x)}
#do something nasty with it
changeFile(fileForChange, folder, new_folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment