-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrename.py
More file actions
32 lines (25 loc) · 836 Bytes
/
Copy pathrename.py
File metadata and controls
32 lines (25 loc) · 836 Bytes
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
27
28
29
30
31
32
'''
批量重命名文件夹中的图片文件
'''
import os
class BatchRename():
def __init__(self):
self.path = '/home/sjq/img/query'
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), 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()