[Python-ideas] Adding optional parameter to shutil.rmtree to not delete root.
Nick Coghlan
ncoghlan at gmail.com
Thu Aug 25 12:44:50 EDT 2016
On 25 August 2016 at 23:14, Victor Stinner <victor.stinner at gmail.com> wrote:
> Maybe add a different function rather add a flag? Something like
> shutil.remove_dir_files().
The typical Python term for the concept would be "clear", giving
shutil.clear_dir(). Like the ".clear()" method on containers, it would
delete the contents, but leave the container itself alone. rmtree()
could then be a thin wrapper around clear_dir() that also deletes the
base directory.
Alternatively, if we wanted to stick with the "rm" prefix, we could
use "shutil.rmcontents()" as the name. The main downside I'd see to
that is that I'd half expect it to work on files as well (truncating
them to a length of zero), while clear_dir() is unambiguous.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list