Created
June 10, 2022 05:41
-
-
Save zephiransas/c0a38db4a3c84ad9a8abb3b54c445742 to your computer and use it in GitHub Desktop.
Move photos downloaded from flickr to a directory by date taken
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
# frozen_string_literal: true | |
source "https://rubygems.org" | |
gem 'exif', '~> 2.2', '>= 2.2.3'% |
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
require 'exif' | |
require 'fileutils' | |
BASE_DIR = "REPLACE_HERE" | |
OUT_DIR = "REPLACE_HERE" | |
idx = 0 | |
Dir.glob(BASE_DIR + "/*.jpg") do |file| | |
puts file | |
data = Exif::Data.new(File.open(file)) | |
dir_name = data[:exif][:date_time_original].slice(0..9).gsub(/:/, "-") | |
puts dir_name | |
Dir.mkdir(OUT_DIR + '/' + dir_name) unless Dir.exists?(OUT_DIR + '/' + dir_name) | |
dest = "#{OUT_DIR}/#{dir_name}/#{File.basename(file)}" | |
FileUtils.mv(file, dest) | |
idx += 1 | |
end | |
puts "Move #{idx} files." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment