-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRe_IMG_Name.py
More file actions
34 lines (26 loc) · 878 Bytes
/
Re_IMG_Name.py
File metadata and controls
34 lines (26 loc) · 878 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
33
# -*- coding: utf-8 -*-
import os
import sys
class ReFileName:
def __init__(self):
reload(sys)
sys.setdefaultencoding('utf8')
positon = os.getcwd()
self.positon =positon
self.__ReName()
def __ReName(self):
list_dirs = os.walk(self.positon, topdown=True)
for root, dirs, files in list_dirs:
num = 0
for name in files:
filename=os.path.join(root,name)
file_format=os.path.splitext(name)[1]
if file_format=='.jpg' or file_format=='.png':
try:
os.rename(filename, filename.replace(name, str(num)+file_format))
except Exception as e:
print e
num+=1
if __name__ == '__main__':
A=ReFileName()
raw_input("Press Enter to terminate.")