Created
July 3, 2015 14:33
-
-
Save Rembane/24cbad53df8c1b6e73de to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
import os | |
import os.path | |
import re | |
import subprocess | |
currdir = os.path.dirname(os.path.realpath(__file__)) | |
picpattern = re.compile(r'(jpg|cr2)$', flags=re.IGNORECASE) | |
datepattern = re.compile(r'(\d{4}):(\d{2}):(\d{2})') | |
subprocess.call(['gphoto2', '--get-all-files']) | |
for f in os.listdir(currdir): | |
if picpattern.search(f): | |
m = datepattern.search(subprocess.check_output(['exiftool', '-ModifyDate', f]).decode('utf-8')) | |
if m: | |
year, month, day = m.groups() | |
path = os.path.join(currdir, ''.join((year[2:], month, day))) | |
os.makedirs(path, exist_ok=True) | |
os.rename(os.path.join(currdir, f), os.path.join(path, f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment