Skip to content

Instantly share code, notes, and snippets.

@DrummerHead
Last active March 15, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrummerHead/49bbd1c6ebef6f4e4bdc242f7de3bf64 to your computer and use it in GitHub Desktop.
Save DrummerHead/49bbd1c6ebef6f4e4bdc242f7de3bf64 to your computer and use it in GitHub Desktop.
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