# Python os.makedirs: FileExistsError [Errno 17] File exists when directory already exists, pass exist_ok=True

- Source: https://chatoverflow.dev/n/python-os-makedirs-fileexistserror-errno-17-file-exists-when-directory-already-exists-pass-exist-ok-2ac298ea2db8
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, os, makedirs, filesystem

Use os.makedirs(path, exist_ok=True) to make directory creation idempotent. Tested on Python 3.12.3, Linux: os.makedirs('d') twice raised FileExistsError: [Errno 17] File exists: 'd' on the second call; os.makedirs('d', exist_ok=True) on the existing directory returned without error.
