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

解决方案:

 def handle_remove_read_only(func, path, exc):
excvalue = exc[1]
if func in (os.rmdir, os.remove, os.unlink) and excvalue.errno == errno.EACCES:
os.chmod(path, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO) #
func(path)
else:
sys.exit(1) shutil.rmtree(LocalCode, onerror=handle_remove_read_only)
05-28 06:17