You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

os.rename()报WinError183文件已存在,但目标文件实际不存在

解决os.rename()/shutil.move()报WinError 183的问题

完整错误信息:

FileExistsError: [WinError 183] Cannot create a file when that file already exists: 
'C:\\Users\\unit0\\OneDrive\\Documentos\\EA Games\\The Sims™ 2 Ultimate Collection\\Downloads\\
test\\[Lilith] Hairs (Coolsims and Newsea)\\[Lilith] Hairs (Coolsims and Newsea)
\\\\[Lilith] Coolsims 109 3t2 DigitalAngels - Io+Pooklet' 
-> 
'C:\\Users\\unit0\\OneDrive\\Documentos\\EA Games\\The Sims™ 2 Ultimate Collection\\Downloads\\
test\\[Lilith] Hairs (Coolsims and Newsea)\\[Lilith] Hairs (Coolsims and Newsea)
\\\\LilithCoolsims1093t2DigitalAngels-IoPooklet'

以下是排查和解决步骤:

  • 手动验证目标文件是否存在:打开文件资源管理器导航到目标路径,开启「显示隐藏文件、文件夹和驱动器」选项,确认是否已有同名(或系统判定为同名)的文件存在。Windows文件系统默认大小写不敏感,若目标文件名仅大小写差异也会触发该错误。

  • 检查文件名隐藏字符:看似不同的文件名可能包含空格、制表符或不可见Unicode字符,导致系统判定重复。用以下代码打印文件名的字符编码对比:

import os
src_path = r'C:\Users\unit0\OneDrive\Documentos\EA Games\The Sims™ 2 Ultimate Collection\Downloads\test\[Lilith] Hairs (Coolsims and Newsea)\[Lilith] Hairs (Coolsims and Newsea)\[Lilith] Coolsims 109 3t2 DigitalAngels - Io+Pooklet'
dst_path = r'C:\Users\unit0\OneDrive\Documentos\EA Games\The Sims™ 2 Ultimate Collection\Downloads\test\[Lilith] Hairs (Coolsims and Newsea)\[Lilith] Hairs (Coolsims and Newsea)\LilithCoolsims1093t2DigitalAngels-IoPooklet'

print("源文件名字符编码:", [ord(c) for c in os.path.basename(src_path)])
print("目标文件名字符编码:", [ord(c) for c in os.path.basename(dst_path)])

若编码存在差异,说明文件名确实不同;若编码高度相似,需排查隐藏字符。

  • 暂停OneDrive同步:路径位于OneDrive目录下,后台同步可能导致文件锁定或缓存冲突。右键任务栏OneDrive图标,选择「暂停同步」,再尝试重命名操作。

  • 简化测试路径:当前路径包含多层重复目录(两层[Lilith] Hairs (Coolsims and Newsea)),可能引发路径解析异常。先将源文件移动到桌面等简单目录,再执行重命名,排除复杂路径的影响。

  • 释放文件占用:检查任务管理器,关闭可能占用该文件的程序(如资源管理器预览窗口、解压软件、The Sims 2游戏进程),确保文件处于可修改状态。

内容的提问来源于stack exchange,提问作者Renan Andrade

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 11:10:41