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

yipeiwu_com5年前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()

以上这篇python 实现对文件夹中的图像连续重命名方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python去除所有html标签的方法

本文实例讲述了python去除所有html标签的方法。分享给大家供大家参考。具体分析如下: 这段代码可以用于去除文本里的字符串标签,不包括标签里面的内容 import re html...

python 画三维图像 曲面图和散点图的示例

用python画图很多是根据z=f(x,y)来画图的,本博文将三个对应的坐标点输入画图: 散点图: import matplotlib.pyplot as plt from mpl_...

python3实现mysql导出excel的方法

python3实现mysql导出excel的方法

Mysql中'employee'表内容如下: # __Desc__ = 从数据库中导出数据到excel数据表中 import xlwt import pymysql class...

python 并发编程 非阻塞IO模型原理解析

python 并发编程 非阻塞IO模型原理解析

非阻塞IO(non-blocking IO) Linux下,可以通过设置socket使其变为non-blocking。当对一个non-blocking socket执行读操作时,流程是...

python列表去重的二种方法

复制代码 代码如下:#第一种def delRepeat(liebiao): for x in liebiao:  while liebiao.count(x...