我有这样的代码
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
如果您不知道密码,则无法提取文件。所以在那种情况下,我真的看不到进度条的意义。
