Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Prepend exif date to file name
#!/usr/bin/env ruby
# Place this script in a folder full of images.
# After execution, it will rename all image files,
# prepending the date of shot taken to the
# original file name.
# https://github.com/tonytonyjan/exif
# gem install exif
require 'exif'
all_files = Dir.entries('.')
jpgs = all_files.select { |file_name| file_name =~ /\.jpg$/ }
jpgs.each do |file_name|
data = Exif::Data.new(File.open(file_name))
date = data
.date_time_original
.to_s
.gsub(/:/, '-')
.gsub(/\s/, '--')
new_name = "#{date}--#{file_name}"
File.rename(file_name, new_name)
puts "#{file_name} renamed to #{new_name}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.