Skip to content

Instantly share code, notes, and snippets.

@joonyou
Created July 16, 2010 02:02
Show Gist options
  • Save joonyou/477818 to your computer and use it in GitHub Desktop.
Save joonyou/477818 to your computer and use it in GitHub Desktop.
rename
#!/usr/bin/env ruby
#
if $*.size < 1
puts "usage: rename \"{file search criteria}\" pattern replacement"
puts "example: rename \"*\" .MOV .mov"
puts " this changes the .MOV to .mov in all files in current directory"
else
files = Dir.glob "#{$*[0]}"
files.each do |f|
begin
File.rename(f, f.gsub($*[1],$*[2]))
rescue
puts "FAILED: #{f}"
puts $!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment