python库 使用shutil来删除文件夹时报PermissionError时的解决方案

 

解决方案:

 1 def handle_remove_read_only(func, path, exc):
 2     excvalue = exc[1]
 3     if func in (os.rmdir, os.remove, os.unlink) and excvalue.errno == errno.EACCES:
 4       os.chmod(path, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO) # 0777
 5       func(path)
 6     else:
 7         sys.exit(1)
 8 
 9 
10 shutil.rmtree(LocalCode, onerror=handle_remove_read_only)

 

posted @ 2019-11-28 11:05  why_so_serious  阅读(1270)  评论(0)    收藏  举报