linux解压win文件目录,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

#include

#include

#include

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()<

return RET_FAILED;

}

if(dstPath.length() == 0)

{

return RET_FAILED;

}

int ret;

QProcess p;

fileName = fileName.replace("//","/");

qDebug()<

if(fileName.at(1) == ':')

{

QString driveId = fileName.left(2);

fileName = fileName.right(fileName.length()-2);

p.execute("cd /d " + driveId);

}

qDebug()<

ret = p.execute("gzip -d " + fileName);

if(ret != 0)

{

qDebug()<

}

qDebug()<

fileName = fileName.left(fileName.length()-3);

if(dstPath.at(1) == ':')

{

dstPath = "//./" + dstPath;

}

qDebug()<

p.execute("tar xvf " + fileName + " -C " + dstPath);

if(ret != 0)

{

qDebug()<

}

qDebug()<

QFile::remove(fileName);

return RET_SUCCESS;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值