6-08 3,740 views
import os
import fnmatch
#path写路径,fnexp写文件后缀.
def iterfindfiles(path, fnexp):
for root, dirs, files in os.walk(path):
for filename in fnmatch.filter(files, fnexp):
yield os.path.join(root, filename)
for filename in iterfindfiles(r"c:\dianzi_book_cate", "*.png"):
#获取文件前缀,和后缀
math = os.path.splitext(filename)[0][20:]
prepath = os.path.splitext(filename)[0][:20]
#重命名
os.rename(filename,prepath+'2015-'+math+'.png')