跳至内容
LinuxNote
用户工具
登录
站点工具
搜索
工具
显示页面
过去修订
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您的足迹:
程序设计:python:照片整理
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
<code python> # -*- coding: utf-8 -*- """ 功能:对照片按照拍摄时间进行归类 使用方法:将脚本和照片放于同一目录,双击运行脚本即可 作者:冰蓝 """ import shutil import os import time import exifread class ReadFailException(Exception): pass def getOriginalDate(filename): try: fd = open(filename, 'rb') except: raise ReadFailException, "unopen file[%s]\n" % filename data = exifread.process_file( fd ) if data: try: t = data['EXIF DateTimeOriginal'] return str(t).replace(":",".")[:7] except: pass state = os.stat(filename) return time.strftime("%Y.%m", time.localtime(state[-2])) def classifyPictures(path): for root,dirs,files in os.walk(path,True): dirs[:] = [] for filename in files: filename = os.path.join(root, filename) f,e = os.path.splitext(filename) if e.lower() not in ('.jpg','.png','.mp4'): continue info = "文件名: " + filename + " " t="" try: t = getOriginalDate( filename ) except Exception,e: print e continue info = info + "拍摄时间:" + t + " " pwd = root +'/'+ t dst = pwd + '/' + filename if not os.path.exists(pwd ): os.mkdir(pwd) print info, dst shutil.copy2( filename, dst ) os.remove( filename ) if __name__ == "__main__": path = "." classifyPictures(path) </code>
程序设计/python/照片整理.txt
· 最后更改: 2023/06/13 05:25 由
127.0.0.1
页面工具
显示页面
过去修订
反向链接
回到顶部