def rmtree(path):
    """shutil.rmtree() but also handle junction points and access errors on Windows.
    """
    if islink(path):
        unlink(path)
    elif os.path.isdir(path):
        for sub in os.listdir(path):
            sub = os.path.join(path, sub)
            if os.path.isfile(sub):
                if not os.access(sub, os.W_OK):
                    # Is the error an access error?
                    os.chmod(sub, stat.S_IWUSR)
                os.unlink(sub)
            else:
                rmtree(sub)
        os.rmdir(path)
    else:
        raise RuntimeError("rmtree called on non-link/folder")
shutil.rmtree() but also handle junction points and access errors on Windows.