Skip to content

Instantly share code, notes, and snippets.

@Rembane
Created July 3, 2015 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rembane/24cbad53df8c1b6e73de to your computer and use it in GitHub Desktop.
Save Rembane/24cbad53df8c1b6e73de to your computer and use it in GitHub Desktop.
#!/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