草庐IT

Python - 操作系统错误 : [WinError 17] The system cannot move the file to a different disk drive:

coder 2023-08-25 原文

我正在使用

os.rename()

尝试在驱动器之间移动 pdf 文件。尝试这个我收到错误:

OSError: [WinError 17] The system cannot move the file to a different disk drive

有人知道包含与 os.rename 类似功能并允许跨磁盘文件传输的函数吗?

最佳答案

os.rename() 更改文件的路径但不移动磁盘上的实际数据。 这就是为什么您不能将它从一个驱动器移动(重命名)到另一个驱动器的原因。

在驱动器之间移动其实就是先复制它,然后再删除源文件。 当您尝试在两个驱动器之间传输文件时,您可以使用 shutil.move() 方法执行此操作

import shutil
shutil.move(src,dest)

关于Python - 操作系统错误 : [WinError 17] The system cannot move the file to a different disk drive:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21116510/

有关Python - 操作系统错误 : [WinError 17] The system cannot move the file to a different disk drive:的更多相关文章

随机推荐