Skip to content

Instantly share code, notes, and snippets.

@handerson
Created August 27, 2016 03:14
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 handerson/c2b900d64b709a336a72dede8419355e to your computer and use it in GitHub Desktop.
Save handerson/c2b900d64b709a336a72dede8419355e to your computer and use it in GitHub Desktop.
Fixes NDS rom names for use with R4 cards
#!/usr/bin/env ruby
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.on('-d n', '--directory=n', 'Set Directory') do |d|
options[:directory] = d
end
opts.on('-h', '--help', 'Displays Help') do
puts opts
exit
end
end.parse!
def clean_name(filename)
filename.gsub(/\A[\d\W]+|\(.+\)|\W/, '')
end
def rename_files(dir)
Dir.foreach(dir) do |item|
next if item == '.' || item == '..'
new_name = clean_name(File.basename(item, '.*')) + File.extname(item)
puts "Renaming #{item} to #{new_name}"
File.rename(item, new_name)
end
end
if options[:directory].nil?
puts 'You must supply a directory'
exit
end
rename_files(options[:directory])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment