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

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

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

标签:python,图像,重命名
0
投稿

猜你喜欢

  • Python操作PDF文件之实现A3页面转A4

    2021-03-06 19:45:06
  • PHP MVC模式在网站架构中的实现分析

    2023-07-22 21:05:14
  • Django原生sql也能使用Paginator分页的示例代码

    2023-11-09 10:00:06
  • MySQL Order By Rand()效率

    2011-01-04 19:34:00
  • python因子分析的实例

    2021-12-29 18:20:44
  • PHP addAttribute()函数讲解

    2023-06-06 09:03:45
  • 关于Thinkphp6的日志问题

    2023-06-06 10:54:23
  • Python cookbook(数据结构与算法)找出序列中出现次数最多的元素算法示例

    2021-04-16 10:50:05
  • Python参数传递机制传值和传引用原理详解

    2023-07-28 11:16:02
  • python创造虚拟环境方法总结

    2021-08-26 18:46:41
  • js倒记时代码,自定义时间改变时间,日期到时事件,日期格式。

    2010-08-08 08:51:00
  • Python实现字符串格式化输出的方法详解

    2023-05-02 20:52:59
  • Python 爬虫多线程详解及实例代码

    2021-01-25 14:05:03
  • ASP中转换unicode编码为gb2312函数

    2007-10-22 17:46:00
  • Python将Excel表格按某列拆分为多个sheet实现过程

    2021-06-11 06:59:54
  • 我的javascript小扎

    2008-08-12 13:04:00
  • PyCharm 安装与使用配置教程(windows,mac通用)

    2023-08-21 01:15:39
  • 教你怎样在Oracle数据库中高速导出/导入

    2009-02-04 16:59:00
  • Python3访问并下载网页内容的方法

    2022-11-12 06:08:39
  • 页面制作的重要性

    2007-10-30 13:14:00
  • asp之家 网络编程 m.aspxhome.com