批量改文件名

#!/usr/bin/python
import os
path1='/root/model/'
file=os.listdir(path1)
num=file.index('index.html')
del file[num]
c=str(file)
c=c.replace('_','.')
c=c.title()
c=c.replace('Model.Php','class.php')
e=list(eval(c))
b=file
a=dict(zip(b,e))

#注意对象的变化,比如字符串用split得出的是列表b=a.split('.');type(b)
for key in a.keys():
os.rename(os.path.join(path1,key),os.path.join(path1,a[key]))

#print(type(key)) --字符串
#print(type(a[key]))

posted on 2016-08-31 14:33  yang68h  阅读(134)  评论(0编辑  收藏  举报