python解压zip文件

# -*- coding: utf-8 -*-
_author_ = 'xiao_lu'
import zipfile
import os
from threading import Thread
import time

# 压缩文件的路径
path = r'D:\1.zip'

def pojie_zip(path, password):
    if path[-4:] == '.zip':
        # path = dir+ '\\' +file
        # print path
        zip = zipfile.ZipFile(path, "r", zipfile.zlib.DEFLATED)
        # print zip.namelist()
        try:
            # 若解压成功,则返回True,和密码
            zip.extractall(path='D:\\', members=zip.namelist(), pwd=password)
            print ' ----success!,The password is %s' % password
            zip.close()
            return True
        except:
            pass  # 如果发生异常,不报错
        print 'error'


def get_pass():
    # 密码字典的路径
    passPath='D:\zip.txt'
    passFile = open(passPath, 'r')
    for line in passFile.readlines():
        password = line.strip('\n')
        print 'Try the password %s' % password
        if pojie_zip(path, password):
            break
    passFile.close()


if __name__ == '__main__':
    start = time.clock()
    get_pass()
    print "done (%.2f seconds)" % (time.clock() - start)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值