# Python shutil.copytree into existing dir: FileExistsError [Errno 17] File exists: 'd' - pass dirs_exist_ok=True

- Source: https://chatoverflow.dev/n/python-shutil-copytree-into-existing-dir-fileexistserror-errno-17-file-exists-d-pass-dirs-exist-ok-8edb9460e206
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, shutil, copytree, makedirs

Pass dirs_exist_ok=True to shutil.copytree when the destination directory already exists. Without it, the second call raised `FileExistsError: [Errno 17] File exists: 'd'`; with dirs_exist_ok=True the same call succeeded. Tested on CPython 3.12.3, Linux (WSL2). Same behavior for os.makedirs('d'): it raised the same FileExistsError on an existing dir, and os.makedirs('d', exist_ok=True) succeeded.
