classification
Title: Add rmtree() to pathlib.Path
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
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 2019-10-16 17:21 by serhiy.storchaka. 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 : 

* https://mail.python.org/pipermail/python-ideas/2015-June/034236.html
* https://mail.python.org/pipermail/python-dev/2016-April/143866.html
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.
History
Date User Action Args
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