Created
April 23, 2012 15:16
-
-
Save brianhempel/2471546 to your computer and use it in GitHub Desktop.
Script for mass renaming of files via Regexp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'fileutils' | |
if ARGV.size < 3 | |
puts <<-USAGE | |
mass_rename [file1 file2 ...] <regexp> <replacement> | |
USAGE | |
end | |
file_names, regexp, replacement = ARGV[0...-2], ARGV[-2], ARGV[-1] | |
file_names.each do |old_name| | |
new_name = old_name.gsub(/#{regexp}/, replacement) | |
if old_name != new_name | |
puts "Renaming \"#{old_name}\"\tto \"#{new_name}\"..." | |
FileUtils.mv(old_name, new_name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment