使用 os.rename() 重命名火影忍者视频文件时出错WinError 123

问题描述

我正在编写一个 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...