Python unrar解压rar压缩文件
原创
©著作权归作者所有:来自51CTO博客作者小龙在山东的原创作品,请联系作者获取转载授权,否则将追究法律责任
安装
解压
from unrar import rarfile
# 源码:https://github.com/matiasb/python-unrar
# 下载UnRAR.dll https://www.rarlab.com/rar_add.htm
# 配置UnRAR.dll位置
# 在系统变量里配置
# UNRAR_LIB_PATH = C:\Program Files (x86)\UnrarDLL\x64\UnRAR64.dll
filename = 'rar压缩包路径'
extract_path = '解压路径'
fp = rarfile.RarFile(filename)
for pwd in range(0, 10000):
# 左对齐,不足补0
pwd = "{0:0>4}".format(pwd)
try:
fp.extractall(pwd=pwd, path=extract_path)
print('Success:', pwd)
break
except Exception:
print(pwd)
pass