shutil.copytree without files

前端 未结 5 2200
刺人心
刺人心 2021-02-13 19:39

I\'m trying use shutil.copytree:

shutil.copytree(SOURCE_DIR, TARGET_DIR, ignore=None)

This copy also files in folder. I need copy only folders

5条回答
  •  天命终不由人
    2021-02-13 20:11

    use distutils.dir_util.create_tree to just copy directory structure (not files)

    note : the argument files is a list of filenames. if you want something that would work as shutils.copytree:

    import os
    import distutils.dir_util
    def copy_tree(source, dest, **kwargs):
        filenames = [os.path.join(path, file_) for path, _, files in os.walk(source) for file_ in files]
        distutils.dir_util.create_tree(dest, filenames, **kwargs)
    

提交回复
热议问题