【问题标题】:How get percentage of password protected rar file extraction in python?如何在 python 中获取受密码保护的 rar 文件提取的百分比?
【发布时间】:2013-09-17 17:04:20
【问题描述】:

我有这样的代码

        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文件提取百分比?

【问题讨论】:

  • 使用可以处理加密 RAR 文件的rarfile
  • @IgnacioVazquez-Abrams 你能解释一下吗?我没有得到你

标签: python python-2.6


【解决方案1】:

查看docs,您似乎应该使用setpassword 为其提供密码。

例子:

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

# Rest of code here

如果您不知道密码,则无法提取文件。所以在那种情况下,我并没有真正看到进度条中的重点。

【讨论】:

    猜你喜欢
    • 2012-09-29
    • 2017-05-23
    • 2020-09-03
    • 1970-01-01
    • 2021-01-23
    • 2012-04-15
    • 2011-04-16
    • 1970-01-01
    • 2013-04-23
    相关资源
    最近更新 更多