import os
import logging

#视频文件路径 这是是 \\ 最后不用 \\ 结尾
VIDEOPATH = "G:\\resources\\计算机\\编程语言\\JavaScript\\李炎恢老师Jquery视频教程+源码"

        
logging.basicConfig(filename='renamefiles.log',level=logging.INFO,
                    format ='%(asctime)s-%(levelname)s----%(message)s',
                    datefmt = '%y-%m-%d %H:%M',
                    filemode = 'w')
                    

# 遍历文件
def renameFile(path):

    filelist = os.listdir(path)
    for file in filelist:
        Oldfile =  os.path.join(path,file)
        if os.path.isdir(Oldfile):
            continue
        filename=os.path.splitext(file)[0]
        filetype=os.path.splitext(file)[1]
        newfilename = filename.replace('【本资源由www.qinglongweb.com收集整理】','')
        Newfile=os.path.join(path,newfilename+filetype)
        os.rename(Oldfile,Newfile)
        logging.info(Newfile)
    
    
    
def main():
    renameFile(VIDEOPATH)
    print("-------------处理完成！--------------");

if __name__ == '__main__':
    main()