Remove directory tree without following symlinks

eryk sun eryksun at gmail.com
Fri Apr 22 14:28:01 EDT 2016


On Fri, Apr 22, 2016 at 12:39 PM, Albert-Jan Roskam
<sjeik_appie at hotmail.com> wrote:
> FYI, Just today I found out that shutil.rmtree raises a WindowsError if the dir is read-
> only (or its contents). Using 'ignore_errors', won't help. Sure, no error is raised, but the
> dir is not deleted either! A 'force' option would be a nice improvement.

Use the onerror handler to call os.chmod(path, stat.S_IWRITE). For
example, see pip's rmtree_errorhandler:

https://github.com/pypa/pip/blob/8.1.1/pip/utils/__init__.py#L105



More information about the Python-list mailing list