问题描述
我正在编写一个 python 脚本来重命名标题混乱的火影忍者视频。代码如下:
import os
import re
def rename_files():
os.chdir(r"C:\Users\Caleb\Videos\Anime\Naruto Shippuden")
files = os.listdir('.')
for file in files:
nameRegex = re.compile(r'.?(Naruto(-?)).'
r'(Shi(p)+(u)+den)'
r'(_-_|\s-\s|\sEpisode\s|-_Season_17_Episode_| Episode |_)'
r'((\d\d\d)(-\d\d\d)?)',re.I)
mo = nameRegex.search(file)
if mo is None:
print(f'({file} Not found)')
continue
ext = os.path.splitext(file)
old_name = ext[0] + ext[1]
new_name = f"{mo.group(1).title()} {mo.group(3).title()},Episode: {mo.group(7)}{ext[1]}"
os.rename(old_name,new_name)
rename_files()
我使用了 os.rename() 但它一直抛出以下错误:
Traceback (most recent call last):
File "C:\Users\Caleb\Desktop\Python\rename_files.py",line 28,in <module>
rename_files()
File "C:\Users\Caleb\Desktop\Python\rename_files.py",line 25,in rename_files
os.rename(old_name,new_name)
OSError: [WinError 123] The filename,directory name,or volume label Syntax is incorrect: '(Hi10)_Naruto_Shippuuden_-_003_(480p)_(SD).mkv' -> 'Naruto Shippuuden,Episode: 003.mkv'
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)