美文网首页
一键解压文件

一键解压文件

作者: 西厌西厌 | 来源:发表于2023-02-19 17:27 被阅读0次
import base64
import os
import tarfile
import gzip
import zipfile

# 对gz类型进行解压
def gzip_file(file):
    c_path = file+"\\logcat_log.tar.gz"
    try:
        g = gzip.GzipFile(mode='rb',fileobj=open(c_path,'rb'))
        open(c_path.replace('.gz',''),'wb').write(g.read())
    except Exception as e:
        print(e)
    else:
        untar(c_path.replace('.gz',''),file+'./',file)
        #print('文件解压成功!')
   
def untar(fname,dirs,origin):
    print("fname="+fname)
    try:
        t = tarfile.open(fname)
        t.extractall(path=dirs)
    except Exception as e:
        print(e)
    else:
        #print('解压tar成功')
        zip_allfile(origin+"\\log")

def zip_allfile(dirs):
    for f in os.listdir(dirs):
        if '.zip' in f:
            zip_file = zipfile.ZipFile(dirs+"\\"+f)
            zip_file.extract(zip_file.namelist()[0],dirs)
    for f in os.listdir(dirs):
        l_file = dirs+"\\"+f
        with open(l_file, "r", encoding="utf-8" ,errors="ignore") as f: 
            for line in f:
                #if 'fatal' in line:
                    #print(line)
                #if 'died' in line:
                    #print(line)
                if 'avc: denied' in line and 'toybox_vendor' not in line:
                    print(line)
       

       

if __name__ == "__main__":
    #modify_name()
    path = 'D:\\log分析\\hx11_dhu_simplelog_20230209155259'
    gzip_file(path)

相关文章

  • winrar创建自解压exe文件

    需求:将已经打包完毕的软件文件根目录制作成一键安装文件。 1、定义自解压文件名,指定创建自解压文件格式选项 2、指...

  • 用电脑自带的WINrar解压缩软件将多个文件、文件夹一键单独打包

    .今天给大家讲解一下用电脑自带的WINrar解压缩软件将多个文件、文件夹一键单独打包或将大文件分割为多个小文件包的...

  • 离线生成EOS公钥和私钥

    离线生成EOS公钥和私钥,下载附件解压后直接打开eosjs-ecc.html这个文件,点击“一键生成EOS公钥和私...

  • shell解压命令

    解压全部 gz文件:gunzip *g 解压zip文件: unzip xxx.zip 解压tar.gz文件:tar...

  • 解压文件

    .bz解压1:bzip2 -d FileName.bz解压2:bunzip2 FileName.bz .bz2解压...

  • 解压文件

    不使用BufferedOutputStream的情况 引入读取输入流,并不知道会读多少字节数据,如果将byte数组...

  • iOS中解压rar文件

    iOS中基于UnrarKit解压rar文件 iOS中解压rar文件,使用UnrarKit框架解压,框架github...

  • 文件复制/解压

    //--------------------复制文件 //--------------------解压文件------

  • Mac 配置Tomcat 8.5.11

    下载Tomcat Tomcat下载地址 复制文件 解压刚才下载的 zip 包.解压文件 将解压的apache-to...

  • word文档操作

    @压缩压下面的那个,解压要解压到文件目录,这样解压的文件都在文件目录里。 @文件里有新建,保存,另存,保存类型一般...

网友评论

      本文标题:一键解压文件

      本文链接:https://www.haomeiwen.com/subject/xdjogktx.html