python [复制目录的所有内容]将目录的所有内容复制到另一个目录#FileOperation

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python [复制目录的所有内容]将目录的所有内容复制到另一个目录#FileOperation相关的知识,希望对你有一定的参考价值。

def copy_dir(src, dst, symlinks=False, ignore=None):
    """
    copy directory from source to destiny
    """
    if not os.path.exists(dst):
        os.makedirs(dst)
    for item in os.listdir(src):
        s = os.path.join(src, item)
        d = os.path.join(dst, item)
        if os.path.isdir(s):
            if os.path.exists(d):
                continue
            shutil.copytree(s, d, symlinks, ignore)
        else:
            shutil.copy2(s, d)

以上是关于python [复制目录的所有内容]将目录的所有内容复制到另一个目录#FileOperation的主要内容,如果未能解决你的问题,请参考以下文章