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.

Title: Add rmtree() to pathlib.Path
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
Status: closed Resolution: duplicate
Dependencies: Superseder: pathlib.Path wants an rmtree method
View: 33498
Assigned To: Nosy List: pitrou, serhiy.storchaka, valorien, xtreak
Priority: normal Keywords:

Created on 2019-10-16 13:55 by valorien, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg354799 - (view) Author: Alori (valorien) Date: 2019-10-16 13:55
pathlib.Path supports deletion of both files (Path.unlink()) and directories (Path.rmdir()).

Unfortunately, Path.rmdir() does not allow deletion of non-empty directories which means users must use shutil.rmtree() when deleting such paths.

Since pathlib.Path already supports file and (empty) directory deletion, adding Path.rmtree(missing_ok=False) would support both the utility and the completeness of pathlib.
msg354805 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-10-16 17:11
There is shutil.rmtree that accepts path objects and is more high level. From the previous discussions with respect to expanding API it's recommended to change the functions already present to accept path objects which shutil.rmtree already does and not to expand pathlib API.

Some related discussions : 

msg354806 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-10-16 17:21
Concur with Karthikeyan.

pathlib.Path provides an object oriented interface to file path operations and to low-level filesystem operations. rmtree() is a high-level and complex operation. Instead of adding more and more complex operations to the Path class we added support of Path (and more generally, path-like objects) in many other functions.
Date User Action Args
2022-04-11 14:59:21adminsetgithub: 82680
2019-10-16 17:21:17serhiy.storchakasetstatus: open -> closed
superseder: pathlib.Path wants an rmtree method
messages: + msg354806

resolution: duplicate
stage: resolved
2019-10-16 17:11:11xtreaksetnosy: + serhiy.storchaka, xtreak, pitrou
messages: + msg354805
2019-10-16 13:55:57valoriencreate