在网上查了一下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

 

相关文章:

  • 2023-03-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-06-27
  • 2021-06-18
猜你喜欢
  • 2021-12-27
  • 2021-09-30
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
相关资源
相似解决方案