Skip to content

Instantly share code, notes, and snippets.

@gunyarakun
Created January 27, 2017 21:58
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 gunyarakun/766c9238268ad56bd6bd5510ea34ec3d to your computer and use it in GitHub Desktop.
Save gunyarakun/766c9238268ad56bd6bd5510ea34ec3d to your computer and use it in GitHub Desktop.
Exif情報を使って年月日時間でファイル名をリネームするRubyスクリプト
#!/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