Created
May 2, 2014 11:35
-
-
Save nag4/ccea3b87bce3d2495bd2 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- coding: utf-8 -*- | |
from PIL import Image | |
import os | |
import shutil | |
# exists src_dir/hoge.jpg, fuga.png, etc... | |
src_dir = "/Users/name/hoge/" | |
# create dst_dir/yyyymmdd/ | |
dst_dir = "/Users/name/fuga/" | |
if os.path.exists(dst_dir) == False: | |
os.mkdir(dst_dir) | |
for root, dirs, files in os.walk(src_dir): | |
for filename in files: | |
try: | |
image = Image.open(src_dir + filename) | |
# 36867 : EXIF DateTimeOriginal | |
date = image._getexif()[36867] | |
yyyy, mm, dd = date[:4], date[5:7], date[8:10] | |
yyyymmdd_dir = os.path.join(dst_dir, yyyy + mm + dd) | |
if os.path.exists(yyyymmdd_dir) == False: | |
os.mkdir(yyyymmdd_dir) | |
dst = os.path.join(yyyymmdd_dir, filename) | |
if os.path.exists(dst) == False: | |
shutil.copy2(src_dir + filename, dst) | |
except Exception as e: | |
# .DS_Store must Die | |
print filename + ' is fail.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment