首页 > 解决方案 > 尝试重命名 Program Files (x86) 中的每个文件时出现 OSError

问题描述

我是 python 的初学者,想搞砸一点,由于当前爆发了冠状病毒,我认为尝试制作一个脚本将它可以重命名的每个文件(避免 Windows 错误)重命名为冠状病毒会很有趣,但是当试图重命名程序文件中的所有内容我得到了一个奇怪的 OSError。到目前为止我从未遇到过这个问题,我不知道如何解决它。(如果可以的话)

import os
PRF = r"C:\Program Files (x86)"
for root in os.walk(PRF)
    os.rename(str(root) , "Coronavirus!")

它给出了这个错误:

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: "('C:\\\\\\\\Program Files (x86)', ['Common Files', 'Internet Explorer', 'Microsoft.NET', 'Reference Assemblies', 'Windows Defender', 'Windows Mail', 'Windows Media Player', 'Windows Multimedia Platform', 'Windows NT', 'Windows Photo Viewer', 'Windows Portable Devices', 'Windows Sidebar', 'WindowsPowerShell'], ['desktop.ini'])" -> 'Coronavirus!'

另外,如果您需要知道我正在虚拟机上执行此操作

标签: python

解决方案


推荐阅读