Python os 批量修改文件名

# -*- coding: utf-8 -*-
import os
#设定文件路径
path=r'D:郭鹏历届真题解析2007-2020'
i=1
#对目录下的文件进行遍历
for file in os.listdir(path):
#判断是否是文件
    file_name=os.path.join(path,file)
    if os.path.isfile(os.path.join(path,file))==True:
#设置新文件名

        start=file.find("P")

        end=file.find(").flv")

        new_name=file[start:end]+".flv"
        os.rename(os.path.join(path,file),os.path.join(path,new_name))
生命在于运动,智慧在于学习!
原文地址:https://www.cnblogs.com/sharer/p/14768952.html