Created
February 2, 2020 02:56
-
-
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
This file contains hidden or 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
# 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