本文实例为大家分享了python实现文件批量重命名的具体代码,供大家参考,具体内容如下
代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# -*- 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