Skip to content

Instantly share code, notes, and snippets.

@mrchrisadams
Forked from chrismear/gist:26268
Created November 18, 2008 21:11
Show Gist options
  • Save mrchrisadams/26273 to your computer and use it in GitHub Desktop.
Save mrchrisadams/26273 to your computer and use it in GitHub Desktop.
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