[Python-ideas] Adding optional parameter to shutil.rmtree to not delete root.
Victor Stinner
victor.stinner at gmail.com
Thu Aug 25 09:14:39 EDT 2016
Maybe add a different function rather add a flag? Something like
shutil.remove_dir_files().
Victor
Le 25 août 2016 4:32 AM, "Nick Jacobson via Python-ideas" <
python-ideas at python.org> a écrit :
> 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
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160825/7898a241/attachment-0001.html>
More information about the Python-ideas
mailing list