Skip to content

Instantly share code, notes, and snippets.

@zephiransas
Created June 10, 2022 05:41
Show Gist options
  • Save zephiransas/c0a38db4a3c84ad9a8abb3b54c445742 to your computer and use it in GitHub Desktop.
Save zephiransas/c0a38db4a3c84ad9a8abb3b54c445742 to your computer and use it in GitHub Desktop.
Move photos downloaded from flickr to a directory by date taken
# frozen_string_literal: true
source "https://rubygems.org"
gem 'exif', '~> 2.2', '>= 2.2.3'%
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