Python修改文件名

Python批量修改文件名

 1 # -*- coding: cp936 -*-
 2 import os
 3 from nt import chdir
 4 path="./files/"
 5 fromstr="转换后"
 6 tostr=""
 7 for root,dirs,files in os.walk(path):
 8     for name in files:
 9         print name
10         print root
11         if fromstr in name:
12             newname=name.replace(fromstr,tostr)
13             print newname
14             os.rename(root+"/"+name,root+"/"+newname)
原文地址:https://www.cnblogs.com/Leechg/p/5446237.html