当前位置: 动力学知识库 > 问答 > 编程问答 >

How can I move files between mounts using Python?

问题描述:

I've been using os.rename to move files in Python. However, it appears that this fails if you try to move files between one mountpoint and another (on Linux).

Is there a Python library or function to move files between mountpoints, similar to mv on Linux?

网友答案:

This is a common caveat with os.rename. The higher level shutil module and it's move method works around this for you by using os.rename() or shutil.copy2() as appropriate.

One thing to keep in mind is that this loses the atomic guarantee that os.rename has if it isn't on the same filesystem.

See https://docs.python.org/2/library/shutil.html#shutil.move

网友答案:

You can use mv using subprocess

from subprocess import check_call

check_call(["mv","src","dest"])
分享给朋友:
您可能感兴趣的文章:
随机阅读: