我有一些节目下载到我的电脑上,但标题完全混淆所以很难找到我想要的剧集,我不想参考wiki来找出哪一集是哪个< / p>
由于有太多的剧集要单独重命名,我决定使用python一次重命名,使用json表存储正确的剧集名称进行比较和替换(剧集都有他们的季节编号和剧集编号所以我可以用它进行比较)
目前,我有这个:
import os
import sys
from random import randint as mathRandom
nameDict={}
#nameDict["Ed.Edd.n.Eddy.S01E01"]={"Name":"Ed Touchables / Nagged to Ed"}
nameDict["Ed.Edd.n.Eddy.S01E02"]={"Name":"Pop Goes the Ed / Over Your Ed"}
nameDict["Ed.Edd.n.Eddy.S01E03"]={"Name":"Sir Ed-a-Lot / A Pinch to Grow an Ed"}
nameDict["Ed.Edd.n.Eddy.S01E04"]={"Name":"Dawn of the Eds / Virt-Ed-Go"}
nameDict["Ed.Edd.n.Eddy.S01E05"]={"Name":"Read All About Ed / Quick Shot Ed"}
nameDict["Ed.Edd.n.Eddy.S01E06"]={"Name":"An Ed Too Many / Ed-n-Seek"}
nameDict["Ed.Edd.n.Eddy.S01E07"]={"Name":"Look into My Eds / Tag Yer Ed"}
nameDict["Ed.Edd.n.Eddy.S01E08"]={"Name":"Fool on the Ed / A Boy and His Ed"}
nameDict["Ed.Edd.n.Eddy.S01E09"]={"Name":"It's Way Ed / Laugh Ed Laugh"}
nameDict["Ed.Edd.n.Eddy.S01E10"]={"Name":"A Glass of Warm Ed / Flea-Bitten Ed"}
nameDict["Ed.Edd.n.Eddy.S01E11"]={"Name":"Who, What, Where, Ed! / Keeping Up with the Eds"}
nameDict["Ed.Edd.n.Eddy.S01E12"]={"Name":"Eds-Aggerate / Oath to an Ed"}
nameDict["Ed.Edd.n.Eddy.S01E13"]={"Name":"Button Yer Ed / Avast Ye Eds"}
path = 'C:/Users/badfitz66/Desktop/EdEddnEddy/Episodes'
os.chdir(path)
for filename in os.listdir(path):
filename_splitext = os.path.splitext(filename)
newSettings = nameDict[filename_splitext[0]].get("Name")
if newSettings is not None :
if nameDict.get(filename_splitext[0]):
os.rename(filename, filename + str(newSettings)+'.mkv')
我正在尝试将作为第一个值的剧集名称(例如:Ed.Edd.n.Eddy.S01E04)更改为剧集编号和季节+每个部分的名称(例如:阅读所有关于Ed / Quick Shot Ed)
但是当我跑步时,我收到了这个错误:
Traceback (most recent call last):
File "C:/Users/badfitz66/Desktop/ah.py", line 33, in <module>
os.rename(filename, filename + str(newSettings)+'.mkv')
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'Ed.Edd.n.Eddy.S01E02.mkv' -> 'Ed.Edd.n.Eddy.S01E02.mkvPop Goes the Ed / Over Your Ed.mkv'
我做错了什么?
答案 0 :(得分:1)
在你的for循环中,剧集是一个字符串,而不是一个字典。因此,您无法使用字符串索引访问其元素。
只需将episode['Name']
替换为episode
,然后重命名我的所有文件。
您只能使用1个循环来完成任务
import os
import sys
nameDict={}
nameDict["test.1"]={"Name":"LOL1.mkv"}
nameDict["test.2"]={"Name":"LOL2.vcl"}
nameDict["test.3"]={"Name":"LOL3.txt"}
nameDict["test.4"]={"Name":"LOL4.py"}
nameDict["test.5"]={"Name":"LOL5.ss"}
nameDict["test.6"]={"Name":"LOL6.lol"}
nameDict["test.7"]={"Name":"LOL7.po"}
path = 'test'
# Loop over all files and directories
for filename in os.listdir(path):
# Get the name
filename_splitext = os.path.splitext(filename)
# print filename_splitext
# Check if we have new file name in nameDict
newSettings = nameDict.get( str(filename_splitext[0]), None)
if newSettings is not None :
# print newSettings
# Rename with new filename
os.rename(os.path.join(path, filename),os.path.join(path, newSettings['Name']))
答案 1 :(得分:0)
在黑暗中拍摄:
尝试使用episode.Name
代替episode["Name"]