Python os 批量修改文件名
时间:2021-05-14 21:03:21
收藏:0
阅读:22
# -*- 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
评论(0)