Last active
March 15, 2018 16:16
-
-
Save DrummerHead/49bbd1c6ebef6f4e4bdc242f7de3bf64 to your computer and use it in GitHub Desktop.
Prepend exif date to file name
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
#!/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