Skip to content

Instantly share code, notes, and snippets.

@elleryq
Created January 2, 2014 09:27
Show Gist options
  • Save elleryq/8216816 to your computer and use it in GitHub Desktop.
Save elleryq/8216816 to your computer and use it in GitHub Desktop.
According the photo's taken date to classify photos like this: your_path/2014/1/1 You have to install exifread: pip install exifread
from __future__ import print_function
import sys
import os
import exifread
import glob
from datetime import datetime
import shutil
def main():
if len(sys.argv)<2:
print("Need arguments")
print("For example: *.jpg d:\\tmp")
sys.exit(-1)
jpgs = glob.glob(sys.argv[1])
outputBase = sys.argv[2]
print(outputBase)
for jpg in jpgs:
print(jpg)
tags = exifread.process_file(open(jpg, "rb"))
if not tags:
continue
takenDate = tags['EXIF DateTimeOriginal']
dt = datetime.strptime(str(takenDate), "%Y:%m:%d %H:%M:%S")
destPath = os.path.join(outputBase, str(dt.year),
str(dt.month), str(dt.day))
if not os.path.exists(destPath):
os.makedirs(destPath)
shutil.copy(jpg, destPath)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment