扣丁学堂Python培训之实现对文件夹中的图像连续重命名方法

2018-10-26 13:41:55 315浏览

今天扣丁学堂Python培训老师给大家分享一篇关于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。


扣丁学堂微信公众号 


关注微信公众号获取更多学习资料 

 

查看更多关于"Python开发资讯"的相关文章>


标签: Python培训 Python视频教程 Python在线视频 Python学习视频

热门专区

暂无热门资讯

课程推荐

微信
微博
15311698296

全国免费咨询热线

邮箱:codingke@1000phone.com

官方群:148715490

北京千锋互联科技有限公司版权所有   北京市海淀区宝盛北里西区28号中关村智诚科创大厦4层
京ICP备12003911号-6   Copyright © 2013 - 2019

京公网安备 11010802030908号