Trier des images par leurs données EXIF

Tue 16 October 2012 | Damien Python
import pyexiv2
import os, shutil
import datetime

DOSSIER_DES_PHOTOS = "/home/vous/votre/dossier"

for filename in os.listdir(DOSSIER_DES_PHOTOS):

    if os.path.isfile(os.path.join(DOSSIER_DES_PHOTOS, filename)):

        print "Traitement de " + filename

        metadata = pyexiv2.ImageMetadata(os.path.join(DOSSIER_DES_PHOTOS, filename))
        metadata.read()

        tag = metadata['Exif.Photo.DateTimeOriginal']
        folder = tag.value.strftime("%Y-%m-%d")

        if os.path.exists(os.path.join(DOSSIER_DES_PHOTOS, folder)) == False:

            os.mkdir(os.path.join(DOSSIER_DES_PHOTOS, folder))
            print os.path.join(DOSSIER_DES_PHOTOS, folder, filename)
            shutil.move(
                os.path.join(DOSSIER_DES_PHOTOS, filename),
                os.path.join(DOSSIER_DES_PHOTOS, folder, filename)
            )