Created
August 27, 2016 03:14
-
-
Save handerson/c2b900d64b709a336a72dede8419355e to your computer and use it in GitHub Desktop.
Fixes NDS rom names for use with R4 cards
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 '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