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)
運行前:
運行結果: