gpt4 book ai didi

python - 如何在 python 中获取受密码保护的 rar 文件提取的百分比?

转载 作者:太空宇宙 更新时间:2023-11-04 03:55:23 25 4
gpt4 key购买 nike

我有这样的代码

        rar = rarfile.RarFile(source_filename)
files = rar.namelist()
count_files =len(files)
i = 0
for f in files:
i = i+1

percent = int((i/float(count_files))*100)
rar.extract(f,dest_dir,self.pwd)
self.emit(percent)
rar.close()

我想在 GUI 应用程序中显示基于文件的 rar 文件提取的百分比。如果 rar 文件未使用密码加密,此代码工作正常。如果 rar 文件受密码保护。rar.namelist() 函数始终给出空列表。如何获取密码加密的 rar 文件中的所有文件名?如何在 python 中获取受密码保护的 rar 文件提取的百分比?

最佳答案

查看 docs看起来你应该使用 setpassword 给它密码。

例子:

rar = rarfile.RarFile(source_filename)
if rar.needs_password():
rar.setpassword('') # whatever the password is

# Rest of code here

如果您不知道密码,则无法提取文件。所以在那种情况下,我真的看不到进度条的意义。

关于python - 如何在 python 中获取受密码保护的 rar 文件提取的百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18855752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com