Skip to content

Instantly share code, notes, and snippets.

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.
# gem install exif
require 'exif'
all_files = Dir.entries('.')
jpgs = { |file_name| file_name =~ /\.jpg$/ }
jpgs.each do |file_name|
data =
date = data
.gsub(/:/, '-')
.gsub(/\s/, '--')
new_name = "#{date}--#{file_name}"
File.rename(file_name, new_name)
puts "#{file_name} renamed to #{new_name}"
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.