This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Consistently add exist_ok / missing_ok parameters to directory creation/deletion functions
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: serhiy.storchaka, timhoffm, valorien
Priority: normal Keywords:

Created on 2019-09-16 22:45 by timhoffm, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg352590 - (view) Author: Tim Hoffmann (timhoffm) * Date: 2019-09-16 22:45
The following functions accept exist_ok/missing_ok parameters:

- Path.mkdir(exist_ok)
- os.makedirs(exist_ok)
- shutil.copytree(dirs_exist_ok) - (https://bugs.python.org/issue20849)
- Path.unlink(missing_ok) - (https://bugs.python.org/issue33123)

For consistency, these functions should support them as well (but currently don't):

- os.makedir(exist_ok)
- os.rmdir(missing_ok)
- Path.rmdir(missing_ok)
- os.removedirs(missing_ok)
- shutil.rmtree(missing_ok)
msg354800 - (view) Author: Alori (valorien) Date: 2019-10-16 14:00
+1
Encountered the same issue today working with Path.rmdir().
Also see a somewhat related issue here: (https://bugs.python.org/issue38499)
msg354809 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-10-16 18:13
os.mkdir() and os.rmdir() are wrappers around corresponding system calls. I do not think they should have additional parameters, especially for functionality which can be easily achieved by wrapping the call with the try/except block.

For shutil.rmtree() see issue29699.

I do not know a good use case for os.removedirs(). Seems it was added for symmetry to os.makedirs(), but it looks dangerous, because it can remove more than was created by os.makedirs(). shutil.rmtree() looks safer and more useful.

Path.rmdir() I left to the maintainers of the pathlib module.
History
Date User Action Args
2022-04-11 14:59:20adminsetgithub: 82375
2019-10-16 18:13:23serhiy.storchakasetmessages: + msg354809
2019-10-16 17:28:39xtreaksetnosy: + serhiy.storchaka
2019-10-16 14:00:58valoriensetnosy: + valorien
messages: + msg354800
2019-09-16 22:45:09timhoffmcreate