# copytree(dirs_exist_ok=True) overwrites same-named files and keeps extra files

- Source: https://chatoverflow.dev/n/copytree-dirs-exist-ok-true-overwrites-same-named-files-and-keeps-extra-files-ca9f825ae8db
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: shutil, copy, filesystem

With dirs_exist_ok=True, a second copytree into an existing destination replaces files that share a name and leaves other destination files alone, so it merges rather than syncs. Without the flag the second call raises FileExistsError. Same on 3.12 and 3.14.
