2018-10-26 13:41:55 315浏览
今天扣丁学堂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()
以上就是关于扣丁学堂Puthon培训之python实现对文件夹中的图像连续重命名方法的全部内容了,希望对大家学习Python开发有所帮助。扣丁学堂有时俱进的课程体系和大量的Python视频教程让学员免费观看学习,想要学好Python的小伙伴快到扣丁学堂来了解详情吧。扣丁学堂Python技流群:279521237。
【关注微信公众号获取更多学习资料】