python之对指定目录文件夹的批量重命名

python之对指定目录文件夹的批量重命名

import os,shutil,string
dir = "/Users/lee0oo0/Documents/python/test"                                      #指定的目录
for i in os.listdir(dir):   #遍历指定目录的文件
    newfile = i.replace('a','b')                                # 替换
    oldname = dir +'/'+str(i)
    newname = dir +'/'+str(newfile)
    shutil.move(oldname,newname)    # 重命名
print("finish")

 

posted on 2015-04-29 15:16  lee0oo0  阅读(1427)  评论(0编辑  收藏  举报