-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulk-move.py
30 lines (25 loc) · 950 Bytes
/
bulk-move.py
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
import os, shutil
from datetime import datetime
from pathlib import Path
from PIL import Image
dirpath = '%MAIN_SOURCE'
paths = sorted(Path(dirpath).iterdir(), key=os.path.getctime)
date_format = '%Y:%m:%d %H:%M:%S'
# Create the directory
parent_dir = '%FINAL_DESTINATION'
if not os.path.isdir(parent_dir):
os.mkdir(parent_dir)
for path in paths:
try:
# The exif code 36867 is the time the file was created (meta data on the actual picture)
date_created = Image.open(path)._getexif()[36867]
date = datetime.strptime(date_created, date_format)
formatted_date = date.strftime('%Y-%m-%d')
# see if the directory exists
tmp_dir = parent_dir + "/" + formatted_date
if not os.path.isdir(tmp_dir):
os.mkdir(tmp_dir)
shutil.copy(path, tmp_dir)
except:
# misc ones are tossed in one folder (burst photos/videos/misc)
shutil.copy(path, parent_dir)