SHOW:
|
|
- or go back to the newest paste.
| 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 | # |