Last active
November 14, 2018 18:19
-
-
Save shouth/9313494e59a76c0b1c47b387260987f1 to your computer and use it in GitHub Desktop.
This file contains 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
from PIL import Image | |
from datetime import datetime | |
from pathlib import Path | |
import imghdr | |
import os | |
import shutil | |
for path in Path.cwd().iterdir(): | |
if Path.is_dir(path) or imghdr.what(path) != 'jpeg': continue | |
exif = Image.open(path)._getexif() | |
if not 0x9003 in exif: continue | |
img_datetime = datetime.strptime(exif[0x9003], '%Y:%m:%d %H:%M:%S') | |
dest = Path.cwd() / str(img_datetime.year) / str(img_datetime.month).zfill(2) | |
if not dest.exists(): os.makedirs(dest) | |
shutil.move(str(path), dest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment