Python實現(xiàn)獲取照片拍攝日期并重命名的方法
本文實例講述了Python實現(xiàn)獲取照片拍攝日期并重命名的方法。分享給大家供大家參考,具體如下:
python獲取照片的拍攝日期并重命名。不支持重復(fù)處理的中斷。
重命名為:拍攝日期__原文件名
import os import exifread def getExif(filename): FIELD = 'EXIF DateTimeOriginal' fd = open(filename, 'rb') tags = exifread.process_file(fd) fd.close() if FIELD in tags: new_name = str(tags[FIELD]).replace(':', '').replace(' ', '_') + os.path.splitext(filename)[1] tot = 1 while os.path.exists(new_name): new_name = str(tags[FIELD]).replace(':', '').replace(' ', '_') + '_' + str(tot) + os.path.splitext(filename)[1] tot += 1 new_name2 = new_name.split(".")[0] + '__' +filename print(new_name2) os.rename(filename, new_name2) else: print('No {} found'.format(FIELD)) for filename in os.listdir('.'): if os.path.isfile(filename): getExif(filename)
有拍攝日期的文件數(shù),年輕時多么愛拍照。。。
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python文件與目錄操作技巧匯總》、《Python文本文件操作技巧匯總》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進階經(jīng)典教程》
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
使用Anaconda創(chuàng)建Python指定版本的虛擬環(huán)境的教程詳解
由于工作的需要和學習的需要,需要創(chuàng)建不同Python版本的虛擬環(huán)境,所以這篇文章主要為大家詳細介紹了如何使用Anaconda創(chuàng)建Python指定版本的虛擬環(huán)境,需要的可以參考下2024-03-03創(chuàng)建Shapefile文件并寫入數(shù)據(jù)的例子
今天小編就為大家分享一篇創(chuàng)建Shapefile文件并寫入數(shù)據(jù)的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11Python開發(fā)之Nginx+uWSGI+virtualenv多項目部署教程
這篇文章主要介紹了Python系列之-Nginx+uWSGI+virtualenv多項目部署教程,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-05-05