码迷,mamicode.com
首页 > 编程语言 > 详细

python unrar 解压缩

时间:2017-09-25 22:04:41      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:[]   ace   from   self   mem   elf   append   model   selected   

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 解压缩

标签:[]   ace   from   self   mem   elf   append   model   selected   

原文地址:http://www.cnblogs.com/dasheng-maritime/p/7593809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!