-
-
Save mrchrisadams/26273 to your computer and use it in GitHub Desktop.
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
require 'csv' | |
codes = [] | |
CSV.open("codes.csv", 'r') do |row| | |
# put the contents of the first column in each row in codes.csv, | |
# into the second column of each of codes | |
codes[row[1].to_i] = row[0] | |
end | |
Dir.chdir 'export' | |
wd = Dir.getwd | |
Dir.glob('*') do |dirname| | |
Dir.chdir(dirname) | |
Dir.glob('*.png') do |filename| | |
# strip out everything in the filename that isn't the number, | |
# and set the new integer value as number | |
number = filename.gsub(/\D/, '').to_i | |
code = codes[number] | |
new_filename = "#{code}.png" | |
puts "Renaming #{filename} to #{new_filename}." | |
File.rename(filename, new_filename) | |
end | |
Dir.chdir(wd) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment