[Python-ideas] Adding optional parameter to shutil.rmtree to not delete root.
Nick Jacobson
nicksjacobson at yahoo.com
Wed Aug 24 22:29:05 EDT 2016
I've been finding that a common scenario is where I want to remove everything in a directory, but leave the (empty) root directory behind, not removing it.
So for example, if I have a directory C:\foo and it contains subdirectory C:\foo\bar and file C:\foo\myfile.txt, and I want to remove the subdirectory (and everything in it) and file, leaving only C:\foo behind.
(This is useful e.g. when the root directory has special permissions, so it wouldn't be so simple to remove it and recreate it again.)
A number of ways to do this have been offered here: http://stackoverflow.com/questions/185936/delete-folder-contents-in-python
But it'd be simpler if there were an optional parameter added to shutil.rmtree, called removeroot. It would default to true so as to not break any backward compatibility. If it's set to false, then it leaves the root directory in place.
Thanks,
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160825/8232071f/attachment.html>
More information about the Python-ideas
mailing list