def copytree(src, dst, symlinks=True):
from shutil import copy2, Error, copystat<EOL>names = os.listdir(src)<EOL>if not Path(dst).exists():<EOL><INDENT>os.makedirs(dst)<EOL><DEDENT>errors = []<EOL>for name in names:<EOL><INDENT>srcname = os.path.join(src, name)<EOL>dstname = os.path.join(dst, name)<EOL>try:<EOL><INDENT>if symlinks and os.path.islink(srcname):<EOL><INDENT>linkto = os.readlink(srcname)<EOL>os.symlink(linkto, dstname)<EOL><DEDENT>elif os.path.isdir(srcname):<EOL><INDENT>copytree(srcname, dstname, symlinks)<EOL><DEDENT>else:<EOL><INDENT>copy2(srcname, dstname)<EOL><DEDENT><DEDENT>except OSError as why:<EOL><INDENT>errors.append((srcname, dstname, str(why)))<EOL><DEDENT>except Error as err:<EOL><INDENT>errors.extend(err.args[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>try:<EOL><INDENT>copystat(src, dst)<EOL><DEDENT>except OSError as why:<EOL><INDENT>if why.winerror is None:<EOL><INDENT>errors.extend((src, dst, str(why)))<EOL><DEDENT><DEDENT>if errors:<EOL><INDENT>raise Error(errors)<EOL><DEDENT>
Modified from shutil.copytree docs code sample, merges files rather than
requiring dst to not exist.