Python 文件重命名的小工具

来源:互联网 发布:重庆网络推广运营 编辑:程序博客网 时间:2024/04/28 16:00
# -*- coding: utf-8 -*-
#python3.3import osimport tracebackdef RenameFile(rootDir,LstoRemove):    for lists in os.listdir(rootDir):        path = os.path.join(rootDir, lists)        #print (path)        for strtoRemove in LstoRemove:            index = path.find(strtoRemove)            if index >= 0:                newPath = path[index + len(strtoRemove):]                print(newPath)                newPath = os.path.join(rootDir, newPath)                try:                    os.rename(path,newPath)                except:                    traceback.print_exc()        if os.path.isdir(path):            RenameFile(path, LstoRemove)    print (rootDir + "  work done!")dir = r"G:\xunlei"LstoRemove = [r"paiohua.com",r"piaohua.com"]#可以扩展自己要去掉的字符RenameFile(dir, LstoRemove)



原创粉丝点击