ps:由于cmd合并ts文件时按照文件名顺序,造成合成视频无法播放,所以文件需要从小到大排序。
文件名本身为纯数字,只要指定字符串长度就可以实现文件按大小顺序排列了。
运行环境:win10 ,Python3.6
编辑器:sublime
运行:cmd
模块:os
copyright©Kevin.G
import os
path=input('')
filelist=os.listdir(path)
for file in filelist:
oldname=os.path.join(path,file)
filename=os.path.splitext(file)[0]
filetype=os.path.splitext(file)[1]
s_width=filename.zfill(4)
newname=os.path.join(path,s_width+filetype)
os.rename(oldname,newname)
# 出现三次运行成功,原文件并没有变化,因为os.rename()写错:
# 1.os.name()
# 2.os.rename=()
print(oldname,'....',newname)
运行前:
运行结果: