问题遇到的现象和发生背景
python中用os.rename()批量修改文件夹中视频文件后缀名报错,(FileNotFoundError: [WinError 2] 系统找不到指定的文件。: '13.ts' -> '13.mp4')
问题相关代码,请勿粘贴截图
import os
files = os.listdir("m3u8/11/")
files.sort(key=lambda x: int(x.split(".")[0]))
for filesname in files:
portion = os.path.splitext(filesname)
if portion[1] == ".ts":
newname = portion[0]+".mp4"
os.rename(filesname, newname)
运行结果及报错内容
Traceback (most recent call last):
File "C:/python/Practice/爬虫第一阶段/07爬取91看剧视频简单版/practice.py", line 16, in <module>
os.rename(filesname, newname)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。: '13.ts' -> '13.m
我的解答思路和尝试过的方法
1、尝试在路径引号前加(r)--无用
2、尝试将“/”更改为“\”、“\”、“//”--无用
3、尝试其他视频格式转换,如.mp4 转.ts、.rmvb--无用
我想要达到的结果
想要实现批量更改文件夹中文件的后缀名