shutil.move -> WindowsError: [错误32] 进程无法访问文件

3 投票
1 回答
4124 浏览
提问于 2025-04-16 07:30

我在用Python 2.5,遇到了一个关于shutil.move的问题。

print(srcFile)
print(dstFile)
shutil.move(srcFile, dstFile)

输出结果:

c:\docume~1\aaa\locals~1\temp\3\tmpnw-sgp
D:\dirtest\d\c\test.txt
...
WindowsError: [Error32] The process cannot access the file because it is being used by 
  another process: 'c:\\docume~1\\aaa\\locals~1\\temp\\3\\tmpnw-sgp'

我是在Windows 2003服务器上使用它的。

那么,这里到底出了什么问题呢?有没有人知道?

最好的祝福。

1 个回答

8

如果你想在你的脚本中继续执行,可以使用:

try:
    shutil.move(srcFile, dstFile)
except WindowsError:
    pass

你遇到的错误32是因为你的电脑或服务器上有其他程序正在使用那个文件。你可能不需要复制临时文件,因为它们的名字并不重要,实际上也不是很重要。

撰写回答