Skip to content

Instantly share code, notes, and snippets.

@randy909
Last active May 30, 2016 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randy909/eaa83b2929ae3dae5d794bf60e5ed0a1 to your computer and use it in GitHub Desktop.
Save randy909/eaa83b2929ae3dae5d794bf60e5ed0a1 to your computer and use it in GitHub Desktop.
Dir.glob('*.{mp3,MP3}') do |file|
match = file.match(/^(.+\()(\d+)(\).+)/)
if (match == nil)
puts "skipping #{file}"
next
end
front, num, back = match.captures
num = num.rjust(2, '0')
newfile = front + num + back
puts "renaming #{file} to #{newfile}"
File.rename(file, newfile)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment