[issue19643] shutil rmtree fails on readonly files in Windows

Paul Moore report at bugs.python.org
Tue Jan 21 16:29:44 CET 2014


Paul Moore added the comment:

It's similar. But the problem is that it only returns a list of errors, it doesn't let you address the error *while the rmtree is in progress*.

The key thing is that if you can fix the problem in onerror, you can avoid needing to restart the whole tree walk, which is the key aspect of rmtree.

As things stand, you can use the set_rw function I showed above, and run the rmtree twice:

    shutil.rmtree('path', onerror=set_rw)
    shutil.rmtree('path')

The first run fixes the error and then the second one deletes the remaining files. But this is clearly inefficient, and makes the limitations of "report errors to the user who can then address them" fairly obvious.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19643>
_______________________________________


More information about the Python-bugs-list mailing list