1 import os 2 3 files = os.listdir("D:QTDownloadRadioQTDownloadRadio - 副本")#列出当前目录下所有的文件 4 5 for filename in files: 6 portion = os.path.splitext(filename)#分离文件名字和后缀 7 print(portion) 8 9 if portion[1] ==".mp4":#根据后缀来修改,如无后缀则空 10 newname = portion[0]+".mp3"#要改的新后缀
##newname = portion[1]+".mp3"#要改的新后缀
11 os.chdir("D:QTDownloadRadioQTDownloadRadio - 副本")#切换文件路径,如无路径则要新建或者路径同上,做好备份 12 os.rename(filename,newname)