zoukankan      html  css  js  c++  java
  • GUN tar for windows Practice

    windows 下调用gzip.exe 和tar.exe解压*.tar.gz压缩包到指定目录

    如:解压D:/test/1.tar.gz 到E:/test/下

    1.切换到压缩包所在目录下

    cd /d D:

     

    2.调用gzip.exe解压.gz压缩文件

    gzip /test/1.tar.gz

     

    3.调用tar.exe解包.tar

    tar xvf /test/1.tar -C //./E:/test/

     

    下面是我自己用QT写的解压函数,windows 和 linux 都适用。

    #include <QtCore/QCoreApplication>
    #include <QFile>
    #include <QProcess>
    #include <QDebug>
    typedef int BOOL;
    #define RET_FAILED -1
    #define RET_SUCCESS 0
    
    BOOL Extract(QString fileName,QString dstPath)
    {
        if(fileName.length()<8 || fileName.right(7)!=".tar.gz")
        {
            qDebug()<<"Extract error:unknown file format,mast be '.tar.gz'";
            return RET_FAILED;
        }
        if(dstPath.length() == 0)
        {
            return RET_FAILED;
        }
        int ret;
        QProcess p;
        fileName = fileName.replace("//","/");
    
        qDebug()<<"Extrating "<<fileName<<" to "<<dstPath<<" ...";
        if(fileName.at(1) == ':')
        {
            QString driveId = fileName.left(2);
            fileName = fileName.right(fileName.length()-2);
            p.execute("cd /d " + driveId);
        }
        qDebug()<<"start to ungzip "<<fileName<<" ...";
        ret = p.execute("gzip -d " + fileName);
    
        if(ret != 0)
        {
            qDebug()<<"gzip returns error code:"<<ret;
        }
        qDebug()<<"ungzip "<<fileName<<" success!";
        fileName = fileName.left(fileName.length()-3);
        if(dstPath.at(1) == ':')
        {
            dstPath = "//./" + dstPath;
        }
        qDebug()<<"start to untar "<<fileName<<" ...";
        p.execute("tar xvf " + fileName + " -C " + dstPath);
        if(ret != 0)
        {
            qDebug()<<"tar returns error code:"<<ret;
        }
        qDebug()<<"untar "<<fileName<<" success!";
        QFile::remove(fileName);
    
        return RET_SUCCESS;
    }


  • 相关阅读:
    C++ 获取ms级的计时
    基于UDP的IP对IP的客户端程序
    stm32 keil生成bin文件
    xmos 加密
    DMX512程序介绍
    WS2812原理及实现
    MFC 通过按钮调用自对话框 给按钮加载位图 给对话框添加背景
    4*4矩阵键盘FPGA扫描实现
    FIFO
    Modelsim建立UVM环境
  • 原文地址:https://www.cnblogs.com/yefengmeander/p/2887944.html
Copyright © 2011-2022 走看看