Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 14th, 2013  |  syntax: Ruby  |  size: 0.70 KB  |  views: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env ruby
  2.  
  3. $annoyingstr = ARGV[0]
  4. $todir = ARGV[1]
  5.  
  6. def addquotestodir
  7.   if $todir.match(/"/)
  8.      "'".concat($todir).concat("'")
  9.  elsif
  10.    if $todir.match(/'/)
  11.      "'".concat($todir).concat("'")
  12.    end
  13.  end
  14. end
  15.  
  16.  
  17.  
  18.  
  19. def batchrename(dirvari)
  20.  addquotestodir
  21.  Dir["#{dirvari}/*"].each do |name|
  22.     new_name = name.gsub($annoyingstr, "")
  23.     puts "#{name} renamed to #{new_name}"
  24.     File.rename(name, new_name)
  25.   end
  26. end
  27.  
  28. def listcwd
  29.   Dir.foreach("#{Dir.pwd}") do |fname|
  30.     puts fname
  31.   end
  32. end
  33.  
  34.  
  35. puts "All instances of #{$annoyingstr} removed from the directory."
  36.  
  37. batchrename($todir)
  38.  
  39. # Current Usage ruby this-script.rb "string" /path/to/dir/*string*
  40. #