Skip to content

Instantly share code, notes, and snippets.

@haqu
Forked from vrybas/rmultirename.rb
Created May 28, 2009 15:47
Show Gist options
  • Save haqu/119393 to your computer and use it in GitHub Desktop.
Save haqu/119393 to your computer and use it in GitHub Desktop.
mass rename
#!/usr/bin/env ruby
def show_usage
puts "Usage: #{$0} [PATTERN] [REPLACEMENT]"
puts "Example: #{$0} htm html"
exit
end
pattern = ARGV[0] || show_usage
replace = ARGV[1] || show_usage
show_usage if pattern == "--help"
`ls -1`.split("\n").each do |filename|
new_filename = filename.gsub(pattern,replace)
system("mv #{filename} #{new_filename}") if new_filename != filename
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment