Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Multifile replacer v 1.00 by Narzew
- # Usage:
- # replace.rb is name of this script
- # replace.rb directory oldphrase newphrase
- # for example:
- # replace.rb dira lorem kek
- # will replace all occurences of word 'lorem' in all files in 'dira' directory by word 'kek'
- # Make backup of files in targetting directory before using this script, because it will modify all files within that directory!
- # (C) Narzew, 30.12.2016
- # Share where you want but keep original credits!
- require 'find'
- dir = ARGV[0]
- oldphrase = ARGV[1]
- newphrase = ARGV[2]
- unless Dir.exist?(dir) || ARGV.size != 3
- print "Multifile replacer by Narzew\nUsage:\nreplace.rb directory oldphrase newphrase\ndirectory - directory of all files\noldphrase - old phrase which be replaced\nnewphrase - this will be in place of oldphrase\n"
- exit
- else
- print "Multifile replacer by Narzew\n"
- end
- Find.find(dir).each{|x|
- next if x == "." || x == ".." || File.directory?(x)
- lambda {
- data = File.read(x)
- File.open(x,'wb'){|w| w.write(data.gsub(oldphrase, newphrase)) }
- print "#{x} processed.\n"
- }.call rescue print "#{x} process failed.\n"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement