python unrar 解压缩

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python unrar 解压缩相关的知识,希望对你有一定的参考价值。

class UNRARModel:
    def __init__(self, filepath):
        self.rar = rarfile.RarFile(filepath)
        self.infolist = self.rar.infolist()

    def extral_list(self, selected_dir):
        selected_infolist = []
        for d in selected_dir:
            for info in self.infolist:
                filename = info.filename.replace("\\", "/")  # in win
                if filename.find(d) != -1 and info.file_size != 0L:
                    selected_infolist.append(info)

        return selected_infolist

    def decompression_list(self, selected_infolist, to_dir):
        """
        extract the Specified directory
        :param selected_infolist: Specified directory
        :param to_dir: destination
        :return:
        """
        self.rar.extractall(path=to_dir, members=selected_infolist)

  

def rar_decompression(from_path, to_path):
    from_path = from_path.replace("\\", "/")  # in win
    rar = rarfile.RarFile(from_path)
    rar.extractall(to_path)

    standout_print("Info: decompression %s to %s finish." % (from_path, to_path))


def remove_file(file_path):
    """
    remove file
    :param file_path:
    :return:
    """
    os.remove(file_path)
    standout_print("Info: remove files %s finish." % file_path)

  

以上是关于python unrar 解压缩的主要内容,如果未能解决你的问题,请参考以下文章

python python zipfile获取并解压缩片段

文件打包与解压缩

mac 解压rar压缩文件

如何在Linux下压缩解压缩文件

迁移站群

linux系统压缩与解压缩工具使用方法