Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding:Utf-8 -*-
- import os, shutil
- from PIL import Image, ExifTags
- from datetime import datetime
- folder = u"E:/Photos/Roma hetvege/"
- destFolder = u"E:/Photos/tmp/"
- # get all .jpg files in folder
- files = [folder + i for i in os.listdir(folder) if i.lower().endswith(".jpg")]
- for i in files:
- # get date from file
- timestamp = os.path.getmtime(i)
- date = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d')
- # load photo into Image module
- img = Image.open(i)
- # get exif data
- exifData = img._getexif()
- # if exif data and type is dictionary
- if exifData and type(exifData) == dict:
- # iterate on dictionary
- for key, value in exifData.items():
- # check if tag in ExifTags
- if key in ExifTags.TAGS:
- # we need only ISO value
- if ExifTags.TAGS[key] == "ISOSpeedRatings":
- # create folders with ISO value
- if not os.path.exists(destFolder + str(value)):
- os.mkdir(destFolder + str(value))
- # copy files
- sourceFileName = os.path.basename(i)
- shutil.copy2(i, destFolder + str(value) + "/" + sourceFileName)
Add Comment
Please, Sign In to add comment