Created
January 27, 2017 21:58
-
-
Save gunyarakun/766c9238268ad56bd6bd5510ea34ec3d to your computer and use it in GitHub Desktop.
Exif情報を使って年月日時間でファイル名をリネームするRubyスクリプト
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
#!/usr/bin/env ruby | |
# gem install exifr | |
require 'find' | |
require 'exifr' | |
require 'fileutils' | |
Find.find('.') do |path| | |
next if File.extname(path) != '.jpg' | |
exif = EXIFR::JPEG.new(path) | |
date = exif.date_time_original | |
new_path = sprintf('%04d-%02d-%02d-%02d.jpg', date.year, date.month, date.day, date.hour) | |
FileUtils.mv(path, File.join(File.dirname(path), new_path)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment