在网上查了一下python实现的图片重命名,工作中刚好用一下。
1 # -*- coding:utf8 -*- 2 import os 3 path = ‘新建文件夹 (2)/‘ 4 filelist = os.listdir(path) 5 for item in filelist: 6 # print(‘item name is ‘,item) 7 if item.endswith(‘.jpg‘): 8 name = item.split(‘.‘,1)[0] 9 src = os.path.join(os.path.abspath(path), item) 10 dst = os.path.join(os.path.abspath(path), name + ‘IR.jpg‘) 11 try: 12 os.rename(src, dst) 13 print(‘rename from %s to %s‘ %(src, dst)) 14 except: 15 continue
原文地址:https://www.cnblogs.com/juluwangshier/p/11445238.html
时间: 2024-10-08 07:48:07