您的错误已包含所需的所有信息:FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'C:\\Users\\satvi_000\\Downloads\\others\\desktop.ini' -> 'C:\\Users\\satvi_000\\Downloads\\desktop.ini'。在
desktop.ini文件是Windows上隐藏的系统文件,包含有关特殊外观或文件夹名称的信息。在
我的Documents文件夹中desktop.ini文件中的示例内容:[.ShellClassInfo]
LocalizedResourceName=@%SystemRoot%\system32\shell32.dll,-21770
IconResource=%SystemRoot%\system32\imageres.dll,-112
IconFile=%SystemRoot%\system32\shell32.dll
IconIndex=-235
您可以看到它包含有关本地化名称的信息(在德语窗口中,它自动显示为Dokumente)、一个特殊图标,有时还包含“virutal folders”的属性。这意味着您应该而不是尝试移动这些文件,因为它们可能会破坏文件夹的正确外观和属性(想想回收站)。在
由于在一个普通的windows系统上有很多的desktop.ini文件,遇到这种问题并不少见。在我的系统中,目前有166个这样的文件:
^{pr2}$
就个人而言,我建议与Nuageux相同,只需try移动并记录/忽略错误:try:
shutil.move(os.path.join(cur_dir,folder,file),os.path.join(cur_dir,file))
except FileExistsError as e:
print("The file {} already exists. Error message: {}".format(os.path.join(cur_dir,file), e))
另一种方法是检查每个文件,如果它的名称是desktop.ini。在