Skip to content

Instantly share code, notes, and snippets.

@45deg
Created March 28, 2019 09:58
Show Gist options
  • Save 45deg/82ebeae4f5b4cb547ec7cccd3fcaca6f to your computer and use it in GitHub Desktop.
Save 45deg/82ebeae4f5b4cb547ec7cccd3fcaca6f to your computer and use it in GitHub Desktop.
import sys
import os
import pathlib
import shutil
import exiftool
target_dir = sys.argv[1]
os.chdir(target_dir)
for fname in os.listdir():
if fname[0] == '.':
continue
with exiftool.ExifTool() as et:
metadata = et.get_metadata(fname)
created = None
for key in ['EXIF:CreateDate','QuickTime:ContentCreateDate']:
if key in metadata:
created = metadata[key].split(' ')[0]
break
if created is None:
folder = "999999"
else:
cs = created.replace(':', '-').split('-')
folder = cs[0] + cs[1]
pathlib.Path(folder).mkdir(parents=True, exist_ok=True)
shutil.move(fname, folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment