#!/usr/bin/env ruby $annoyingstr = ARGV[0] $todir = ARGV[1] def addquotestodir if $todir.match(/"/) "'".concat($todir).concat("'") elsif if $todir.match(/'/) "'".concat($todir).concat("'") end end end def batchrename(dirvari) addquotestodir Dir["#{dirvari}/*"].each do |name| new_name = name.gsub($annoyingstr, "") puts "#{name} renamed to #{new_name}" File.rename(name, new_name) end end def listcwd Dir.foreach("#{Dir.pwd}") do |fname| puts fname end end puts "All instances of #{$annoyingstr} removed from the directory." batchrename($todir) # Current Usage ruby this-script.rb "string" /path/to/dir/*string* #