def copytree(src, dst, overwrite=False, ignore_list=None, debug=False):
    """
    Copy a tree of files over.

    Ignores a file if it already exists at the destination.
    """
    if ignore_list is None:
        ignore_list = []
    if debug:
        print('copytree {} to {}'.format(src, dst))
    for child in Path(src).iterdir():
        if debug:
            print("  on file {}".format(child))
        if child.name not in ignore_list:
            if child.is_dir():
                new_dir = Path(dst) / child.relative_to(src)
                new_dir.mkdir(exist_ok=True)
                # call recursively
                copytree(child, new_dir, overwrite, ignore_list, debug)
            elif child.is_file():
                new_file = new_dir = Path(dst) / child.relative_to(src)
                if debug:
                    print("    to file {}".format(new_file))
                if new_file.exists():
                    if overwrite:
                        new_file.unlink()
                        shutil.copy2(child, new_file)
                else:
                    shutil.copy2(child, new_file)
        else:
            if debug:
                print("  Skipping copy of {}".format(child))
def copytree ( src , dst , overwrite = False , ignore_list = None , debug = False ) : if ignore_list is None : ignore_list = [ ] if debug : print ( 'copytree {} to {}' . format ( src , dst ) ) for child in Path ( src ) . iterdir ( ) : if debug : print ( "  on file {}" . format ( child ) ) if child . name not in ignore_list : if child . is_dir ( ) : new_dir = Path ( dst ) / child . relative_to ( src ) new_dir . mkdir ( exist_ok = True ) copytree ( child , new_dir , overwrite , ignore_list , debug ) elif child . is_file ( ) : new_file = new_dir = Path ( dst ) / child . relative_to ( src ) if debug : print ( "    to file {}" . format ( new_file ) ) if new_file . exists ( ) : if overwrite : new_file . unlink ( ) shutil . copy2 ( child , new_file ) else : shutil . copy2 ( child , new_file ) else : if debug : print ( "  Skipping copy of {}" . format ( child ) )
Copy a tree of files over.

    Ignores a file if it already exists at the destination.