网络编程
位置:首页>> 网络编程>> Python编程>> python 实现对文件夹中的图像连续重命名方法

python 实现对文件夹中的图像连续重命名方法

作者:Xiaoli_Coding  发布时间:2022-11-04 02:04:08 

标签:python,图像,重命名

python实现的对文件夹中的图像进行连续的重命名方法:


import os

class BatchRename():
def __init__(self):
 self.path = 'C:/Users/zxl/Desktop/tr'

def rename(self):
 filelist = os.listdir(self.path)
 total_num = len(filelist)
 i = 101
 for item in filelist:
  if item.endswith('.jpg'):
   src = os.path.join(os.path.abspath(self.path), item)
   dst = os.path.join(os.path.abspath(self.path), str(i) + '.jpg')
   try:
    os.rename(src, dst)
    print 'converting %s to %s ...' % (src, dst)
    i = i + 1
   except:
    continue
 print 'total %d to rename & converted %d jpgs' % (total_num, i)

if __name__ == '__main__':
demo = BatchRename()
demo.rename()

来源:https://blog.csdn.net/u010682375/article/details/77161688

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com