Skip to content

Instantly share code, notes, and snippets.

@blacktm
Created February 2, 2020 02:56
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 blacktm/6a6acd5599f876b47e7920487d4c9e18 to your computer and use it in GitHub Desktop.
Save blacktm/6a6acd5599f876b47e7920487d4c9e18 to your computer and use it in GitHub Desktop.
A Ruby script to rename HEIC and MOV files with date taken in Exif data on macOS
# Requires exiftool, install using Homebrew:
# brew install exiftool
require 'time'
Dir.glob('*.{heic,mov}') do |file|
puts "Renaming #{file}"
case File.extname(file)
when '.heic'
tag = '-DateTimeOriginal'
when '.mov'
tag = '-CreationDate'
end
time = Time.strptime(`exiftool #{tag} #{file} | awk '{ print $4 " " $5 }'`, '%Y:%m:%d %H:%M:%S')
filename = File.basename(file, File.extname(file))
File.rename(file, time.strftime('%Y-%m-%d--%H-%M-%S') + File.extname(file))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment