def rmtree(top):
    for root, dirs, files in os.walk(top, topdown=False):
        for name in files:
            filename = os.path.join(root, name)
os.chmod(filename, stat.S_IWUSR)
os.remove(filename)
for name in dirs:
    os.rmdir(os.path.join(root, name))
os.rmdir(top)
shutil.rmtree fails on Windows with 'Access is denied'