python实现图片文件批量重命名
作者:零尾 时间:2023-08-10 03:39:57
本文实例为大家分享了python实现文件批量重命名的具体代码,供大家参考,具体内容如下
代码:
# -*- coding:utf-8 -*-
import os
class ImageRename():
def __init__(self):
self.path = 'D:/xpu/paper/plate_data'
def rename(self):
filelist = os.listdir(self.path)
total_num = len(filelist)
i = 0
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), '0000' + format(str(i), '0>3s') + '.jpg')
os.rename(src, dst)
print 'converting %s to %s ...' % (src, dst)
i = i + 1
print 'total %d to rename & converted %d jpgs' % (total_num, i)
if __name__ == '__main__':
newname = ImageRename()
newname.rename()
来源:https://blog.csdn.net/lwplwf/article/details/78368229
标签:python,文件,重命名
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
asp如何验证信用卡是否可用?
2010-06-10 18:39:00
pytorch 两个GPU同时训练的解决方案
2023-07-04 11:03:55
opencv3/C++图像像素操作详解
2021-04-23 08:29:26
![](https://img.aspxhome.com/file/2023/1/105061_0s.jpg)
Python入门教程(八)PythonCasting用法
2021-11-14 02:20:41
![](https://img.aspxhome.com/file/2023/2/81522_0s.png)
JS对象数组中如何匹配某个属性值
2024-04-18 09:39:42
![](https://img.aspxhome.com/file/2023/4/136364_0s.png)
xorm根据数据库生成go model文件的操作
2024-01-16 00:29:22
Laravel使用PHPQRCODE实现生成带有LOGO的二维码图片功能示例
2024-05-03 15:28:12
python实现股票历史数据可视化分析案例
2021-12-20 00:29:10
![](https://img.aspxhome.com/file/2023/1/82631_0s.png)
vue-music关于Player播放器组件详解
2024-04-28 09:26:11
![](https://img.aspxhome.com/file/2023/4/133024_0s.jpg)
Python基于React-Dropzone实现上传组件的示例代码
2021-04-01 19:53:03
python深度学习TensorFlow神经网络模型的保存和读取
2022-03-18 06:49:01
![](https://img.aspxhome.com/file/2023/4/87904_0s.png)
python 平衡二叉树实现代码示例
2022-04-24 03:20:34
![](https://img.aspxhome.com/file/2023/4/134874_0s.png)
一个asp简单购物车教程
2007-09-17 11:02:00
ASP ,IP地址分段计算
2008-04-13 06:55:00
设计哲学与跨界
2009-08-18 12:25:00
Python入门学习指南分享
2023-09-02 15:02:21
![](https://img.aspxhome.com/file/2023/1/124681_0s.png)
Python协程实践分享
2023-09-01 05:50:51
![](https://img.aspxhome.com/file/2023/5/62875_0s.png)
SpringMVC4+MyBatis+SQL Server2014实现数据库读写分离
2024-01-23 05:07:22
![](https://img.aspxhome.com/file/2023/8/83118_0s.png)
Spring数据库多数据源路由配置过程图解
2024-01-26 11:23:55
![](https://img.aspxhome.com/file/2023/6/70356_0s.png)
基于Python采集爬取微信公众号历史数据
2023-04-11 15:16:13
![](https://img.aspxhome.com/file/2023/2/82762_0s.png)