【问题标题】:OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect :OSError: [WinError 123] 文件名、目录名或卷标语法不正确:
【发布时间】:2022-01-16 13:49:27
【问题描述】:

您好,我需要找到重命名 mp4 文件的解决方案:

    list_of_choice = ("satisfying","satisfying video","the most satisfying","most oddly satisfying","satisfying videos","the most satisfying video in the world","oddly satisfying videos","sand and slime","ASMR vertical","best oddly satisfying","best oddly satisfying video","satisfying video for sleep","oddly satisfying video to help you sleep","stress relief","satisfaction","no music satisfying","slime","satisfying video to make you sleep","original resource","funny videos") 
    word = random.choice(list_of_choice) 
    list_of_choice = ("satisfying","satisfying video","the most satisfying","most oddly satisfying","satisfying videos","the most satisfying video in the world","oddly satisfying videos","sand and slime","ASMR vertical","best oddly satisfying","best oddly satisfying video","satisfying video for sleep","oddly satisfying video to help you sleep","stress relief","satisfaction","no music satisfying","slime","satisfying video to make you sleep","original resource","funny videos") 
    word1 = random.choice(list_of_choice) 

    filename = word +"~"+ word1 + "~" + "#Shorts"
    file = "output" + f"{number:03}" + ".mp4"
    os.rename(file, filename +".mp4" )

文件名应该是文件名,文件的旧名是文件我这样做是因为我可以把它放到循环中

错误:

OSError: Windows can not read a string 

【问题讨论】:

  • 请填写预期的文件名

标签: python windows error-handling


【解决方案1】:

Windows 不允许您在文件名或路径中使用管道字符 "|"。

不妨试试:

filename = word +"~"+ word1 + "~" + "#Shorts"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-07
    • 2020-03-24
    • 2021-01-07
    • 1970-01-01
    • 2021-04-11
    • 2020-07-30
    • 2017-05-27
    • 2020-04-08
    相关资源
    最近更新 更多