python 重命名再練習

import os
path=input('')
filelist=os.listdir(path)
for file in filelist:
    filetype=os.path.splitext(file)[1]
    if filetype=='.ts':
        filename=os.path.splitext(file)[0]
        name_width=filename.zfill(8)
        oldname=os.path.join(path,file)
        newname=os.path.join(path,name_width+filetype)
        os.rename(oldname,newname)
        print(oldname,'....',newname)
    

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章