根据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文件压缩处理,支持压缩解压文件夹的更多相关文章

  1. Linux命令(16)压缩,解压文件

    tar: 简介:tar命令只是把目录打包成一个归档(文件),并不负责压缩.在tar命令中可以带参数调用gzip或bzip2压缩.因为gzip和bzip2只能压缩单个文件. 在linux下是不需要后缀名 ...

  2. 关于Java解压文件的一些坑及经验分享(MALFORMED异常)

    文章也已经同步到我的csdn博客: http://blog.csdn.net/u012881584/article/details/72615481 关于Java解压文件的一些坑及经验分享 就在本周, ...

  3. java批量解压文件夹下的所有压缩文件(.rar、.zip、.gz、.tar.gz)

    // java批量解压文件夹下的所有压缩文件(.rar..zip..gz..tar.gz) 新建工具类: package com.mobile.utils; import com.github.jun ...

  4. .NET使用ICSharpCode.SharpZipLib压缩/解压文件

    SharpZipLib是国外开源加压解压库,可以方便的对文件进行加压/解压 1.下载ICSharpCode.SharpZipLib.dll,并复制到bin目录下 http://www.icsharpc ...

  5. SpringMVC上传压缩文件,解压文件,并检测上传文件中是否有index.html

    SpringMVC上传压缩文件,解压文件,并检测上传文件中是否有index.html 说明: 1.环境:SpringMVC+Spring+Tomcat7+JDK1.7 2.支持 zip和rar格式的压 ...

  6. 【转载】.NET压缩/解压文件/夹组件

    转自:http://www.cnblogs.com/asxinyu/archive/2013/03/05/2943696.html 阅读目录 1.前言 2.关于压缩格式和算法的基础 3.几种常见的.N ...

  7. 本地上传文件至服务器的技巧(linux文件压缩及解压文件)

    linux(ubuntu)文件解压及压缩文件 ubuntu支持文件的解压及压缩功能, 如果ubuntu上面没有安装过unzip工具的话,可以通过下面命令安装: sudo apt-get install ...

  8. C# 压缩、解压文件夹或文件(带密码)

    今天梳理一下项目中用到的压缩.解压文件夹或文件的方法,发现因为需求不同,已经用了好几个不同组件.今天就好好整理记录下,别下次遇到需求又重头开始了. DotNetZip DotNetZip是一个开源的免 ...

  9. Unity3D研究院之LZMA压缩文件与解压文件

    原地址:http://www.xuanyusong.com/archives/3095 前两天有朋友告诉我Unity的Assetbundle是LZMA压缩的,刚好今天有时间那么就研究研究LZMA.它是 ...

  10. AIX系统上压缩与解压文件

    压缩. 命令格式: #tar -cvf (或xvf)+文件名+设备 C:是本地到其他设备 x:是其他设备到本地 r:是追加,比如打包时,将其他文件追加进来使用该参数. t:显示tar包里的内容,但还原 ...

随机推荐

  1. 使用Python扫描端口情况

    #!/usr/bin/python# -*- coding:utf8 -*-# Python:          2.7.8# Platform:        Windows# Authro:    ...

  2. UIView与CALayer的区别,很详细

    研 究Core Animation已经有段时间了,关于Core Animation,网上没什么好的介绍.苹果网站上有篇专门的总结性介绍,但是似乎原理性的东西不多,看得人云山雾罩,感觉,写那篇东西的人, ...

  3. java工程项目里,在一个包里面,不能出现同名的类名,这问题是刚接触java才会遇到的,特别是新手一般都没有建立包,而是使用默认的,易出现同名的类名,导致eclipse提示错误

    java工程项目里,在一个包里面,不能出现同名的类名,这问题是刚接触java才会遇到的,特别是新手一般都没有建立包,而是使用默认的,易出现同名的类名,导致eclipse提示错误. 问题: 创建了一个工 ...

  4. flipsnap--手机屏幕水平滑动框架

    在很多手机应用中,大家都会见过这样一种效果:当手指横向滑动屏幕时,屏幕上的页面会向左或向右滑动. 下面介绍一下当用HTML5+CSS3开发手机应用时解决这类效果的一款js框架:flipsnap. fl ...

  5. 数据库中存储日期的字段类型究竟应该用varchar还是datetime ?

    背景: 前段时间在百度经验看到一篇文章<如何在电脑右下角显示你(爱人)的名字>,之前也听过这个小技巧,但没真正动手设置过.所以出于好奇就实践了一下. 设置完成后的效果例如以下.右下角的时间 ...

  6. 韩玉琪 《Linux内核分析》MOOC课程

    http://www.cnblogs.com/hyq20135317/p/5422516.html http://mooc.study.163.com/course/USTC-1000029000

  7. iOS UIScrollView 你可能不知道的奇技淫巧

    iOS 的 UIScrollView 可以说是十分强大,巧妙地运用它可以得到一些意想不到的效果.本文将举几个 ScrollView 不常见运用的例子. 自带信息应用 这个界面既可以上下卷动,也可以左右 ...

  8. Map 迭代 两种方法

    Map 迭代 两种方法 Map<String, String> map=new HashMap<String,String>(); map.put("1", ...

  9. 重载,重写和super

    1.重载的概念:----->在同一个类中,允许存在同名函数,但它们的参数个数或者参数类型不同即可.public static void main(String[] args){System.ou ...

  10. document.documentElement.style判断浏览器是否支持Css3属性

    1.document.documentElement.style 属性定义了当前浏览器支持的所有Css属性 包括带前缀的和不带前缀的 例如:animation,webkitAnimation,msAn ...