Last active
December 24, 2015 16:25
-
-
Save borgle/2b42aa27044340ddcac1 to your computer and use it in GitHub Desktop.
【更新根据exif读取时间】图片太多,写个脚本整理图片到子文件夹,按照图片的创建时间整理。
This file contains hidden or 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import os,time,shutil,sys | |
import exifread | |
folder = os.path.join(os.path.dirname(__file__), "a") | |
for fname in os.listdir(folder): | |
fpath = os.path.join(folder,fname) | |
sys.stdout.write(u"\r正在处理 %s" % fpath) | |
sys.stdout.flush() | |
if os.path.isfile(fpath): | |
try: | |
fd = open(fpath, 'rb') | |
data = exifread.process_file(fd) | |
fd.close() | |
if data: | |
t = data['EXIF DateTimeOriginal'] | |
newfolder = os.path.join(folder, str(t)[:7].replace(":", "")) | |
except: | |
pass | |
if not newfolder: | |
attrs = os.stat(fpath) | |
newfolder = os.path.join(folder,time.strftime("%Y%m", time.localtime(attrs.st_ctime))) | |
if not os.path.exists(newfolder): | |
os.mkdir(newfolder) | |
shutil.move(fpath, os.path.join(newfolder,fname)) | |
sys.stdout.write("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment