代码之家  ›  专栏  ›  技术社区  ›  Tim

shutil.move->windowserror:[error32]进程无法访问文件

  •  1
  • Tim  · 技术社区  · 15 年前

    我使用的是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'
    

    我在Windows2003服务器上使用它。

    那么,这里怎么了?有人知道吗?

    谨致问候。

    1 回复  |  直到 8 年前
        1
  •  6
  •   Jakob Bowyer    15 年前

    如果要继续执行脚本,请使用:

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

    获取错误32的原因是计算机或服务器上有另一个进程正在使用该文件。您可能不想复制临时文件,因为它们的名称并不重要。