python 移动文件失败_不能在python中移动文件?错误13权限被拒绝

您的错误已包含所需的所有信息: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。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值