zip和unzip类下载地址:https://download.csdn.net/download/bigtree_mfc/11244981
先将zip.h、zip.cpp、unzip.h、unzip.cpp放入工程
使用下面的函数就可以了
// 返回True表示没有错误,返回False表示有错误发生,
// strDstPath,目标文件夹,strZipName解压的文件名(含绝对路径)
BOOL 工程名::Unzip(CString strDstPath, CString strZipName)
{
BOOL bExistError = FALSE;
SetCurrentDirectory(strDstPath);
HZIP hz = OpenZip(strZipName, 0);
if (hz == NULL)
{
return FALSE;
}
ZIPENTRY ze;
GetZipItem(hz, -1, &ze);
int numitems = ze.index;
for(int i = 0;i<numitems;i++)
{
GetZipItem(hz, i, &ze);
DWORD dwRet = UnzipItem(hz, i, ze.name);
// 解压有错误
if(dwRet != 0)
{
CString strLog;
strLog.Format(TEXT("[CProcessLogic::Unzip]文件解压错误:%s"), ze.name);
//uilog(strLog);
bExistError = TRUE;
}
}
CloseZip(hz);
return !bExistError;
}
使用方法:
Unzip(解压后的目标路径, 要解压的文件路径+文件名);//解压缩
注意这个只能解压zip格式,不能解压rar文件