跨平台的zip文件压缩处理,支持压缩解压文件夹

2023-02-25,,

根据minizip改写的模块,需要zlib支持

输出的接口:

 #define RG_ZIP_FILE_REPLACE    0
#define RG_ZIP_FILE_APPEND 1 //压缩文件夹目录,递归压缩
//szDir是需要压缩的目录,dstLevel是压缩的目录在压缩包里面的层次标识
//可直接指定""
//szZipFile压缩包的文件名
//replaceFlag指定替换或者是追加进压缩包
int DoZipDir(const char* szDir, const char* dstLevel, const char* szZipFile, int replaceFlag); //压缩单个文件,szFile是文件名,其它参数解析同上
int DoZipFile(const char* szFile, const char* dstLevel, const char* szZipFile, int replaceFlag); //解压缩文件
//szZipFile是需要解压的压缩包文件名
//指定需要解压到的目录,直接指定为"",解压至当前目录
int DoUnzip(const char* szZipFile, const char* szTargetDir); //从压缩包里面解压单个文件出来
//srcFileToExtract对应压缩文件时的dstLevel
//其它参数解析同上
int DoUnzipFile(const char* szZipFile, const char* srcFileToExtract, const char* szTargetDir);

本文仅仅提供封装的api,zlib库和info-zip请自行下载

其它涉及的代码可以下载minizip或者info-zip,推荐使用minizip,本代码是在minizip的基础上修改而来,支持跨平台

 /*
minizip.c
Version 1.1, February 14h, 2010
sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) Modifications of Unzip for Zip64
Copyright (C) 2007-2008 Even Rouault Modifications for Zip64 support on both zip and unzip
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
*/ #ifdef _DEBUG
#pragma comment(lib, "../../lib/win32/libzd.lib")
#else
#pragma comment(lib, "../../lib/win32/libz.lib")
#endif #ifndef _WIN32
#ifndef __USE_FILE_OFFSET64
#define __USE_FILE_OFFSET64
#endif
#ifndef __USE_LARGEFILE64
#define __USE_LARGEFILE64
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#ifndef _FILE_OFFSET_BIT
#define _FILE_OFFSET_BIT 64
#endif
#endif #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h> #ifdef _LINUX
# include <utime.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <unistd.h>
#include <dirent.h>
#else
# include <direct.h>
# include <io.h>
#endif #include "zip.h"
#include "stdstring.h"
#include <vector>
#include "comfun.h" using namespace std; // #ifdef _WIN32
// #define USEWIN32IOAPI
// #include "iowin32.h"
// #endif #define WRITEBUFFERSIZE (16384)
#define MAXFILENAME (256) #ifdef _WIN32
static uLong filetime(const char *f, tm_zip *tmzip, uLong *dt)
/*char *f; name of file to get info on */
/* tm_zip *tmzip; return value: access, modific. and creation times */
/*uLong *dt; dostime */
{
int ret = ;
{
FILETIME ftLocal;
HANDLE hFind;
WIN32_FIND_DATAA ff32; hFind = FindFirstFileA(f,&ff32);
if (hFind != INVALID_HANDLE_VALUE)
{
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+,((LPWORD)dt)+);
FindClose(hFind);
ret = ;
}
}
return ret;
}
#else
#ifdef _LINUX
static uLong filetime(const char *f, tm_zip *tmzip, uLong *dt)
/*char *f; name of file to get info on */
/*tm_zip *tmzip; return value: access, modific. and creation times */
/*uLong *dt; dostime */
{
int ret=;
struct stat s; /* results of stat() */
struct tm* filedate;
time_t tm_t=; if (strcmp(f,"-")!=)
{
char name[MAXFILENAME+];
int len = strlen(f);
if (len > MAXFILENAME)
len = MAXFILENAME; strncpy(name, f,MAXFILENAME-);
/* strncpy doesnt append the trailing NULL, of the string is too long. */
name[ MAXFILENAME ] = '\0'; if (name[len - ] == '/')
name[len - ] = '\0';
/* not all systems allow stat'ing a file with / appended */
if (stat(name,&s)==)
{
tm_t = s.st_mtime;
ret = ;
}
}
filedate = localtime(&tm_t); tmzip->tm_sec = filedate->tm_sec;
tmzip->tm_min = filedate->tm_min;
tmzip->tm_hour = filedate->tm_hour;
tmzip->tm_mday = filedate->tm_mday;
tmzip->tm_mon = filedate->tm_mon ;
tmzip->tm_year = filedate->tm_year; return ret;
}
#else
uLong filetime(char *f, tm_zip *tmzip, uLong *dt)
{
return ;
}
#endif
#endif static int check_exist_file(const char* filename)
{
FILE* ftestexist;
int ret = ;
ftestexist = fopen64(filename,"rb");
if (ftestexist==NULL)
ret = ;
else
fclose(ftestexist); return ret;
} static int isLargeFile(const char* filename)
{
int largeFile = ;
ZPOS64_T pos = ;
FILE* pFile = fopen64(filename, "rb"); if(pFile != NULL)
{
int n = fseeko64(pFile, , SEEK_END); pos = ftello64(pFile); if(pos >= 0xffffffff)
largeFile = ; fclose(pFile);
} return largeFile;
} static int DoZipFile(zipFile zf, const char* srcFile, const char* dstLevel)
{
if(zf == NULL || srcFile == NULL) return __LINE__; int err=;
int size_buf=;
void* buf=NULL;
FILE * fin;
int size_read;
const char* filenameinzip = srcFile;
const char *savefilenameinzip;
zip_fileinfo zi;
int zip64 = ; zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = ;
zi.dosDate = ;
zi.internal_fa = ;
zi.external_fa = ;
filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); zip64 = isLargeFile(filenameinzip); /* The path name saved, should not include a leading slash. */
/*if it did, windows/xp and dynazip couldn't read the zip file. */
savefilenameinzip = dstLevel;
while( savefilenameinzip[] == '\\' || savefilenameinzip[] == '/' )
{
savefilenameinzip++;
} err = zipOpenNewFileInZip3_64(zf, savefilenameinzip, &zi,
NULL, , NULL, , NULL /* comment*/,
Z_DEFLATED,
Z_DEFAULT_COMPRESSION,,
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
NULL, , zip64); if (err != ZIP_OK)
printf("error in opening %s in zipfile\n",filenameinzip);
else
{
fin = fopen64(filenameinzip,"rb");
if (fin==NULL)
{
err=ZIP_ERRNO;
printf("error in opening %s for reading\n",filenameinzip);
}
} if (err == ZIP_OK)
{
size_buf = WRITEBUFFERSIZE;
buf = (void*)malloc(size_buf);
if (buf==NULL)
{
printf("Error allocating memory\n");
err = ZIP_INTERNALERROR;
}
else
{
do
{
err = ZIP_OK;
size_read = (int)fread(buf,,size_buf,fin);
if (size_read < size_buf)
if (feof(fin)==)
{
printf("error in reading %s\n",filenameinzip);
err = ZIP_ERRNO;
} if (size_read>)
{
err = zipWriteInFileInZip (zf,buf,size_read);
if (err<)
{
printf("error in writing %s in the zipfile\n",
filenameinzip);
} }
} while ((err == ZIP_OK) && (size_read>)); free(buf);
}
} if (fin)
fclose(fin); if (err<)
err=ZIP_ERRNO;
else
{
err = zipCloseFileInZip(zf);
if (err!=ZIP_OK)
printf("error in closing %s in the zipfile\n",
filenameinzip);
} return ;
} int DoZipFile(const char* strFile, const char* dstLevel, const char* strZipFile, int replaceFlag)
{
int openMode = APPEND_STATUS_CREATE;
if (check_exist_file(strZipFile))
{
if (replaceFlag == RG_ZIP_FILE_APPEND)
{
openMode = APPEND_STATUS_ADDINZIP;
}
else
{
openMode = APPEND_STATUS_CREATE;
}
} zipFile zf;
zf = zipOpen64(strZipFile, openMode);
if (zf)
{
CStdString strDstLevel;
if(dstLevel) strDstLevel = dstLevel;
strDstLevel.Trim();
if(strDstLevel.IsEmpty())
{
strDstLevel = strFile;
if(strDstLevel.Right() == "\\" || strDstLevel.Right() == "/")
strDstLevel = strDstLevel.Left(strDstLevel.GetLength() - );
int nFind = strDstLevel.ReverseFind('\\');
if(nFind == -) nFind = strDstLevel.ReverseFind('/');
if(nFind != -)
strDstLevel = strDstLevel.Mid(nFind);
} if (strDstLevel.Left() == "\\" || strDstLevel.Left() == "/")
strDstLevel = strDstLevel.Right(strDstLevel.GetLength() - ); DoZipFile(zf, strFile, strDstLevel.c_str());
zipClose(zf, NULL);
return ;
} return ;
} static int GetFilesFromDir(const char* strDir, vector<CStdString> &_fileInfo)
{ #ifdef _WIN32
CStdString strFind = strDir;
CStdString strPath;
if (strFind.Right() != "\\")
{
strFind += "\\";
}
strPath = strFind;
strFind += "*.*"; WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile(strFind, &wfd);
if (hFind != INVALID_HANDLE_VALUE)
{
while(FindNextFile(hFind, &wfd))
{
if (strcmp(wfd.cFileName, ".") == || strcmp(wfd.cFileName, "..") == )
{
continue;
}
CStdString strFilePath = strPath + wfd.cFileName;
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
GetFilesFromDir(strFilePath.c_str(), _fileInfo);
}
else
{
_fileInfo.push_back(strFilePath);
}
}
FindClose(hFind);
return ;
} return __LINE__;
#else
struct stat statbuf;
struct dirent *dirp;
DIR *dp;
const char* szPath = strDir; if(lstat(szPath, &statbuf) < )
{
perror("lstat");
return __LINE__;
}
if(S_ISDIR(statbuf.st_mode) == )
{
_fileInfo.push_back(szPath);
return ;
} if((dp = opendir(szPath)) == NULL)
{
perror("opendir");
return __LINE__;
} while((dirp = readdir(dp)) != NULL)
{
if(strcmp(dirp->d_name, ".") == ||
strcmp(dirp->d_name, "..") == )
continue; std::string subDir = string(szPath) + "/";
subDir += dirp->d_name;
if(dirp->d_type == DT_REG)
{
_fileInfo.push_back(subDir);
}
else if(dirp->d_type == DT_DIR)
{
GetFilesFromDir(subDir.c_str(), _fileInfo);
}
} closedir(dp);
#endif
} int DoZipDir(const char* strDir, const char* dstLevel, const char* strZipFile, int replaceFlag)
{
int openMode = APPEND_STATUS_CREATE;
if(check_exist_file(strZipFile))
{
if (replaceFlag == RG_ZIP_FILE_APPEND)
{
openMode = APPEND_STATUS_ADDINZIP;
}
else
{
remove(strZipFile);
openMode = APPEND_STATUS_CREATE;
}
} CStdString strDstLevel;
if(dstLevel) strDstLevel= dstLevel;
strDstLevel.Trim();
if(strDstLevel.IsEmpty()) { //use current dir path as zip file path level
strDstLevel = strDir;
if(strDstLevel.Right() == "/" || strDstLevel.Right() == "\\") //remove the last slash
strDstLevel = strDstLevel.Left(strDstLevel.GetLength() - ); int nFind = strDstLevel.ReverseFind('\\'); //now get the dst level in zip file
if(nFind == -) nFind = strDstLevel.ReverseFind('/');
if(nFind != -) strDstLevel = strDstLevel.Mid(nFind);
} //add pending slash
#ifdef _WIN32
if(strDstLevel.Right() != "\\") strDstLevel += "\\";
#else
if(strDstLevel.Right() != "/") strDstLevel += "/";
#endif //remove slash at the beginning of the string
if (strDstLevel.Left() == "\\" || strDstLevel.Left() == "/")
strDstLevel = strDstLevel.Right(strDstLevel.GetLength() - ); zipFile zf;
zf = zipOpen64(strZipFile, openMode);
if (zf)
{
vector<CStdString> _fileInfo;
GetFilesFromDir(strDir, _fileInfo);
for (size_t i = ; i < _fileInfo.size(); ++i)
{
CStdString strFilePath = _fileInfo[i];
CStdString strFileLevel;
int nFind = strFilePath.Find(strDir);
if(nFind != -) strFileLevel = strFilePath.Mid(strlen(strDir)); if (strFileLevel.Left() == "\\" || strFileLevel.Left() == "/")
strFileLevel = strFileLevel.Right(strFileLevel.GetLength() - ); strFileLevel = strDstLevel + strFileLevel;
strFileLevel.Replace("\\", "/"); DoZipFile(zf, strFilePath.c_str(), strFileLevel.c_str());
// printf("%s\n%s\n", strFilePath.c_str(), strFileLevel.c_str());
} zipClose(zf, NULL);
return ;
} return __LINE__;
} #ifdef _TESTZIP
int main(int argc, char* argv[])
{
if(argc < )
{
printf("Usage: %s zipfile filetozip\n", argv[]);
getchar();
return ;
}
const char* szZipFile = argv[];
bool bFirst = true;
for(int i = ; i < argc; ++i)
{
const char* filetozip = argv[i];
DWORD dwAttr = GetFileAttributes(filetozip);
if(dwAttr == INVALID_FILE_ATTRIBUTES)
{
printf("invalid file name: %s\n", filetozip);
continue;
}
if(dwAttr & FILE_ATTRIBUTE_DIRECTORY)
{
DoZipDir(filetozip, "", szZipFile,
bFirst ? RG_ZIP_FILE_REPLACE : RG_ZIP_FILE_APPEND);
bFirst = false;
}
else if(dwAttr & FILE_ATTRIBUTE_NORMAL)
{
DoZipFile(filetozip, "", szZipFile,
bFirst ? RG_ZIP_FILE_REPLACE : RG_ZIP_FILE_APPEND);
bFirst = false;
}
} getchar(); return ;
} #endif

解压缩API实现,其中的CStdString可以使用CString代替,接口与CString一致。

其它涉及的代码可以下载minizip或者info-zip,推荐使用minizip,本代码是在minizip的基础上修改而来,支持跨平台

 /*
miniunz.c
Version 1.1, February 14h, 2010
sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) Modifications of Unzip for Zip64
Copyright (C) 2007-2008 Even Rouault Modifications for Zip64 support on both zip and unzip
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
*/ #ifndef _WIN32
#ifndef __USE_FILE_OFFSET64
#define __USE_FILE_OFFSET64
#endif
#ifndef __USE_LARGEFILE64
#define __USE_LARGEFILE64
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#ifndef _FILE_OFFSET_BIT
#define _FILE_OFFSET_BIT 64
#endif
#endif #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h> #ifdef _LINUX
#include <unistd.h>
#include <utime.h>
#include <sys/stat.h>
#include <sys/types.h>
#else
#include <direct.h>
#include <io.h>
#include <Windows.h>
#endif #include "unzip.h"
#include "stdstring.h" #define CASESENSITIVITY (0)
#define WRITEBUFFERSIZE (8192)
#define MAXFILENAME (256) /*
#ifdef _WIN32
#define USEWIN32IOAPI
#include "iowin32.h"
#endif
*/
/*
mini unzip, demo of unzip package usage :
Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT
if it exists
*/ /* change_file_date : change the date/time of a file
filename : the filename of the file where date/time must be modified
dosdate : the new date at the MSDos format (4 bytes)
tmu_date : the SAME new date at the tm_unz format */
static void change_file_date(const char *filename, uLong dosdate, tm_unz tmu_date)
{
#ifdef _WIN32
HANDLE hFile;
FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE,
,NULL,OPEN_EXISTING,,NULL);
GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
DosDateTimeToFileTime((WORD)(dosdate>>),(WORD)dosdate,&ftLocal);
LocalFileTimeToFileTime(&ftLocal,&ftm);
SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
CloseHandle(hFile);
#else
#ifdef _LINUX
struct utimbuf ut;
struct tm newdate;
newdate.tm_sec = tmu_date.tm_sec;
newdate.tm_min=tmu_date.tm_min;
newdate.tm_hour=tmu_date.tm_hour;
newdate.tm_mday=tmu_date.tm_mday;
newdate.tm_mon=tmu_date.tm_mon;
if (tmu_date.tm_year > )
newdate.tm_year=tmu_date.tm_year - ;
else
newdate.tm_year=tmu_date.tm_year ;
newdate.tm_isdst=-; ut.actime=ut.modtime=mktime(&newdate);
utime(filename,&ut);
#endif
#endif
} /* mymkdir and change_file_date are not 100 % portable
As I don't know well Unix, I wait feedback for the unix portion */ static int mymkdir(const char* dirname)
{
int ret=;
#ifdef _WIN32
ret = _mkdir(dirname);
#else
#ifdef _LINUX
ret = mkdir (dirname,);
#endif
#endif
return ret;
} int makedir (const char *newdir)
{
char *buffer ;
char *p;
int len = (int)strlen(newdir); if (len <= )
return ; buffer = (char*)malloc(len+);
if (buffer==NULL)
{
printf("Error allocating memory\n");
return UNZ_INTERNALERROR;
}
strcpy(buffer,newdir); if (buffer[len-] == '/') {
buffer[len-] = '\0';
}
if (mymkdir(buffer) == )
{
free(buffer);
return ;
} p = buffer+;
while ()
{
char hold; while(*p && *p != '\\' && *p != '/')
p++;
hold = *p;
*p = ;
if ((mymkdir(buffer) == -) && (errno == ENOENT))
{
printf("couldn't create directory %s\n",buffer);
free(buffer);
return ;
}
if (hold == )
break;
*p++ = hold;
}
free(buffer);
return ;
} static int do_extract_currentfile(unzFile uf, const char* password)
{
char filename_inzip[];
char* filename_withoutpath;
char* p;
int err=UNZ_OK;
FILE *fout=NULL;
void* buf;
uInt size_buf; unz_file_info64 file_info;
uLong ratio=;
err = unzGetCurrentFileInfo64(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,,NULL,); if (err!=UNZ_OK)
{
printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
return err;
} size_buf = WRITEBUFFERSIZE;
buf = (void*)malloc(size_buf);
if (buf==NULL)
{
printf("Error allocating memory\n");
return UNZ_INTERNALERROR;
} p = filename_withoutpath = filename_inzip;
while ((*p) != '\0')
{
if (((*p)=='/') || ((*p)=='\\'))
filename_withoutpath = p+;
p++;
} if ((*filename_withoutpath)=='\0')
{
mymkdir(filename_inzip);
}
else
{
const char* write_filename; write_filename = filename_inzip; err = unzOpenCurrentFilePassword(uf,password);
if (err==UNZ_OK)
{
fout=fopen64(write_filename,"wb"); /* some zipfile don't contain directory alone before file */
if ((fout==NULL) &&
(filename_withoutpath!=(char*)filename_inzip))
{
char c=*(filename_withoutpath-);
*(filename_withoutpath-)='\0';
makedir(write_filename);
*(filename_withoutpath-)=c;
fout=fopen64(write_filename,"wb");
} if (fout==NULL)
{
printf("error opening %s\n",write_filename);
}
}
else
{
printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err);
} if (fout!=NULL)
{
do
{
err = unzReadCurrentFile(uf,buf,size_buf);
if (err<)
{
printf("error %d with zipfile in unzReadCurrentFile\n",err);
break;
}
if (err>)
if (fwrite(buf,err,,fout)!=)
{
printf("error in writing extracted file\n");
err=UNZ_ERRNO;
break;
}
}
while (err>);
if (fout)
fclose(fout); if (err==UNZ_OK)
change_file_date(write_filename,file_info.dosDate,
file_info.tmu_date);
} if (err==UNZ_OK)
{
err = unzCloseCurrentFile (uf);
if (err!=UNZ_OK)
{
printf("error %d with zipfile in unzCloseCurrentFile\n",err);
}
}
else
unzCloseCurrentFile(uf); /* don't lose the error */
} free(buf);
return err;
} static int do_extract(unzFile uf, const char* password)
{
uLong i;
unz_global_info64 gi;
int err;
FILE* fout=NULL; err = unzGetGlobalInfo64(uf,&gi);
if (err!=UNZ_OK)
printf("error %d with zipfile in unzGetGlobalInfo \n",err); for (i=;i<gi.number_entry;i++)
{
if (do_extract_currentfile(uf, password) != UNZ_OK)
break; if ((i+) < gi.number_entry)
{
err = unzGoToNextFile(uf);
if (err!=UNZ_OK)
{
printf("error %d with zipfile in unzGoToNextFile\n",err);
break;
}
}
} return ;
} static int do_extract_onefile(unzFile uf, const char* filename, const char* password)
{
int err = UNZ_OK;
if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
{
printf("file %s not found in the zipfile\n",filename);
return ;
} if (do_extract_currentfile(uf, password) == UNZ_OK)
return ;
else
return ;
} int DoUnzip(const char* szZipFile, const char* szTargetDir)
{
if (szZipFile == NULL)
{
return __LINE__;
} CStdString dirname;
if(szTargetDir) dirname = szTargetDir;
dirname.Trim(); unzFile uf = unzOpen64(szZipFile);
if (uf)
{
#ifdef _WIN32
if (!dirname.IsEmpty() && _chdir(dirname.c_str()))
#else
if (!dirname.IsEmpty() && chdir(dirname.c_str()))
#endif
{
printf("Error changing into %s, aborting\n", dirname.c_str());
return __LINE__;
} do_extract(uf, NULL); unzClose(uf);
return ;
} return __LINE__;
} int DoUnzipFile(const char* szZipFile, const char* srcFileToExtract, const char* szTargetDir)
{
if (szZipFile == NULL)
{
return __LINE__;
} CStdString dirname;
if(szTargetDir) dirname = szTargetDir;
dirname.Trim(); unzFile uf = unzOpen64(szZipFile);
if (uf)
{
#ifdef _WIN32
if (!dirname.IsEmpty() && _chdir(dirname.c_str()))
#else
if (!dirname.IsEmpty() && chdir(dirname.c_str()))
#endif
{
printf("Error changing into %s, aborting\n", dirname.c_str());
return __LINE__;
} do_extract_onefile(uf, srcFileToExtract, NULL); unzClose(uf);
return ;
} return __LINE__;
} #ifdef _TESTUNZIP
int main(int argc, char* argv[])
{
if(argc < )
{
printf("Usage: %s zipfile\n", argv[]);
return ;
} bool bExtractSingalFile = false;
for(int i = ; i < argc; ++i)
{
if(strcmp(argv[i], "-s") == )
{
if(i + < argc)
{
i++;
const char* filetoextract = argv[i];
printf("extract singal file %s\n", filetoextract);
i++;
if(i < argc)
{
DoUnzipFile(argv[i++], filetoextract, NULL);
}
}
}
else
DoUnzip(argv[i], NULL);
} return ;
}
#endif

跨平台的zip文件压缩处理,支持压缩解压文件夹的相关教程结束。

《跨平台的zip文件压缩处理,支持压缩解压文件夹.doc》

下载本文的Word格式文档,以方便收藏与打印。