Created
March 28, 2019 09:58
-
-
Save 45deg/82ebeae4f5b4cb547ec7cccd3fcaca6f 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
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