python 获取 exif 并 批量重命名图片?
(初学皮毛)下面的代码出现了进程占用的情况,有哪位大哥帮忙看看:
import exifreadimport os
def group_imgs(path):
file = os.listdir(path)
src = ''
image = ''
tags = ''
iname = ''
for i in file:
src = path + '/' + i
image = open(src, 'rb')
tags = exifread.process_file(image)
if 'EXIF DateTimeOriginal' in tags:
iname = str(tags['EXIF DateTimeOriginal']).replace(' ', '-')
os.rename(src, iname + i[-4:])
image.close()
group_imgs('G:/itest')
回答:
os.rename()
前关闭打开的文件,像这样
with open(src, 'rb') as image: tags = exifread.process_file(image)
if ....:
....
os.rename(...)
以上是 python 获取 exif 并 批量重命名图片? 的全部内容, 来源链接: utcz.com/p/937744.html