如何使用Python克隆文件? [英] How to clone files with Python?

查看:88
本文介绍了如何使用Python克隆文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在macOS上使用bash,我可以使用 cp -c 创建COW文件克隆.有没有提供相同功能的Python库?Shutil中的复制功能似乎没有提到克隆.

Using bash on macos I can create COW file clones with cp -c. Is there a Python library that provides the same functionality? The copy functions in shutil doesn't seem to mention cloning.

在APFS克隆上: https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/APFS_Guide/Features/Features.html

在BSD克隆文件上: http://www.manpagez.com/man/2/clonefile/

On BSD clonefile: http://www.manpagez.com/man/2/clonefile/

推荐答案

Python标准库不支持克隆文件.

The Python standard library does not support cloning files.

要在子进程中使用 cp -c 克隆文件,可以使用以下功能:

To clone a file using cp -c in a subprocess you can use this function:

def clonefile(source, dest):
    subprocess.check_output(["cp", "-c", source, dest])

这篇关于如何使用Python克隆文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆