-
Notifications
You must be signed in to change notification settings - Fork 1
/
transfer.rb
58 lines (45 loc) · 1.25 KB
/
transfer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'exifr'
require 'fileutils'
require 'progress_bar'
# Bash:
# sudo mount -t drvfs D: /mnt/h
# sudo mount -t drvfs '\\192.168.1.100\Multimedia\Photos' /mnt/Photos
# path = 'H:\DCIM\102D7000'
path = '/mnt/h/DCIM/102D7000'
# destination = '\\\\192.168.1.100\Multimedia\Photos\\'
destination = '/mnt/Photos/'
def get_image_date_time(file_path)
exif = EXIFR::TIFF.new(file_path)
exif.date_time
rescue
exif = EXIFR::JPEG.new(file_path)
exif.date_time
end
count = 0
errors = []
items = Dir.entries(path)
bar = ProgressBar.new(items.count)
items.each do |item|
bar.increment!
next if %w[. ..].include?(item)
count += 1
file_path = File.join(path, item)
begin
date = get_image_date_time(file_path)
dir = date.strftime('%Y-%m-%d')
destination_folder = File.join(destination, dir)
if File.exist?(File.join(destination_folder, item))
# print ' Already exist!'
else
FileUtils.mkdir_p(destination_folder)
FileUtils.cp(file_path, File.join(destination_folder, item))
end
rescue StandardError => ex
errors << { path: file_path, exception: ex }
end
end
puts "#{count} images"
unless errors.empty?
puts "#{errors.length} errors!"
errors.each { |error| puts "#{error[:path]}: #{error[:exception]}" }
end