今天为了批量处理下电脑里的文件,拿Python实现了遍历文件夹内的文件,并修改文件名字的脚本。
在代码中 rootdir 变量是需要遍历的目录,大家可以自行更改。
import os import os.path rootdir = "E:\wamp\www" for parent,dirnames,filenames in os.walk(rootdir): for dirname in dirnames: print "parent is:" + parent print "dirname is" + dirname for filename in filenames: print "parent is:" + parent print "filename is:" + filename print "flename replace:" + filename.replace("_IObitDel","") print "the full name of the file is:" + os.path.join(parent,filename) print "the full name of the file is:" + os.path.join(parent,filename.replace("_IObitDel","")) os.rename(os.path.join(parent,filename),os.path.join(parent,filename.replace("_IObitDel","")))
文章的脚注信息由WordPress的wp-posturl插件自动生成