栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Windows上,shutil.rmtree失败,显示“访问被拒绝”

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Windows上,shutil.rmtree失败,显示“访问被拒绝”

检查以下问题:

python脚本在Windows中以什么用户身份运行?

显然,答案是将文件/文件夹更改为非只读,然后将其删除。

这是@Sridhar
Ratnakumar在评论中提到的

onerror()
处理程序
pathutils.py

def onerror(func, path, exc_info):    """    Error handler for ``shutil.rmtree``.    If the error is due to an access error (read only file)    it attempts to add write permission and then retries.    If the error is for another reason it re-raises the error.    Usage : ``shutil.rmtree(path, onerror=onerror)``    """    import stat    if not os.access(path, os.W_OK):        # Is the error an access error ?        os.chmod(path, stat.S_IWUSR)        func(path)    else:        raise


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/636864.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号