-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename.py
31 lines (25 loc) · 815 Bytes
/
rename.py
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
import os
import random
import pickle
import logging
logging.basicConfig(level=logging.DEBUG,filename='logging.log')
logger = logging.getLogger(__name__)
logger.info('This is a log info for NAME.py')
save_data="./save_data.pkl"
f_namelist=[]
with open(save_data,"rb") as f:
f_namelist=pickle.load(f)
for dirpath,_,filenames in os.walk('./'):
for oldname,time,title in f_namelist:
#if title:
newname=time+" "+title+".htm"
if newname not in filenames: #防止重命名
try:
os.rename(oldname,newname)
except Exception as e:
print(e)
logger.info(e)
continue
#print('rename dir fail\r\n')\
elif newname in filenames:
logger.info(newname," already exist")