This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.moore
Recipients paul.moore
Date 2014-07-22.19:54:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
It would be useful for shutil.rmtree to have a "force" argument that overrode read-only permission issues, essentially replicating the behaviour of the -f flag in rm -rf (Unix) and the -force parameter of del (Windows Powershell).

It's possible to use the onerror callback to implement this, but it's tricky to get right in a cross-platform manner. See, which recommends

def onerror(func, path, exc_info):
    if not os.access(path, os.W_OK):
        os.chmod(path, stat.S_IWUSR)

and which recommends

def remove_readonly(func, path, excinfo):
    os.chmod(path, stat.S_IWRITE)

It's not clear whether either of these is portable, though (the former looks to me like it's Unix-specific and the latter like it's for Windows, but I'm not sure).

Having the functionality available in the standard library function directly avoids having people write tricky and potentially buggy code for what is a pretty common situation. (In particular, this comes up a lot in code that deletes git checkouts on Windows, where git makes parts of the .git directory readonly).
Date User Action Args
2014-07-22 19:54:30paul.mooresetrecipients: + paul.moore
2014-07-22 19:54:30paul.mooresetmessageid: <>
2014-07-22 19:54:30paul.moorelinkissue22040 messages
2014-07-22 19:54:30paul.moorecreate