def copytree(src, dst, symlinks=False, ignore=None):
<EOL>if not os.path.exists(dst):<EOL><INDENT>os.makedirs(dst)<EOL>shutil.copystat(src, dst)<EOL><DEDENT>lst = os.listdir(src)<EOL>if ignore:<EOL><INDENT>excl = ignore(src, lst)<EOL>lst = [x for x in lst if x not in excl]<EOL><DEDENT>for item in lst:<EOL><INDENT>s = os.path.join(src, item)<EOL>d = os.path.join(dst, item)<EOL>if symlinks and os.path.islink(s):<EOL><INDENT>if os.path.lexists(d):<EOL><INDENT>os.remove(d)<EOL><DEDENT>os.symlink(os.readlink(s), d)<EOL>try:<EOL><INDENT>st = os.lstat(s)<EOL>mode = stat.S_IMODE(st.st_mode)<EOL>os.lchmod(d, mode)<EOL><DEDENT>except:<EOL><INDENT>pass  <EOL><DEDENT><DEDENT>elif os.path.isdir(s):<EOL><INDENT>copytree(s, d, symlinks, ignore)<EOL><DEDENT>else:<EOL><INDENT>shutil.copy2(s, d)<EOL><DEDENT><DEDENT>
copytree that works even if folder already exists