我正在尝试使用 Python 制作文件重命名器。我能够成功地从 Wikipedia 中获取剧集列表,但是在制作重命名文件时,我遇到了很多差异。我想要的是,我想使用与 if 条件匹配的扩展名,而不是最后的“.mkv”。有没有办法退货?
extensions = ('.webm','.mkv','.flv','.vob','.ogv',
'.ogg','.drc','.gif','.gifv','.mng','.avi','.mov',
'.qt','.wmv','.yuv','.rm','.rmvb','.asf','.amv','.mp4',
'.m4p', '.m4v','.mpg', '.mp2', '.mpeg', '.mpe', '.mpv',
'.mpg', '.mpeg', '.m2v','.m4v','.svi','.3gp','.3g2','.mxf',
'.roq','.nsv','.f4v', '.f4p', '.f4a' ,'.f4b','.srt')
list = f.readlines()
y = 0
num = 1
for filename in os.listdir(path):
if filename.endswith(extensions):
os.rename(path+"\\"+filename,path+"\\"+str(num)+' - '+list[int(y)].strip('\n')+'.mkv') #instead of mkv, I want extension which was matched in the above if condition.
y += 1
num += 1