|
7#
楼主 |
发表于 2021-3-30 19:00:29
|
只看该作者
/*
HZIP newZipFile = CreateZip(full_filepath_,0);
ZIP_Folder(str_path, str_path, full_filepath_,newZipFile);
CloseZip(newZipFile); //关闭zip文件
*/
ZIP_Folder(const wxString &in_epub_folder,
const wxString &in_folder_old,
const wxString &out_filename,
HZIP newZipFile)
{
if (!wxFileName::Exists(in_folder))
{
return ;
}
//建立一个空的压缩文件
//HZIP newZipFile = CreateZip(out_filename,0);
TCHAR* ch_folder;
TCHAR* ch_filename;
TCHAR* ch_fullpath;
wxDir dir(in_folder);
wxString filename;
wxString file_and_folder_short_name;
int iPos=0;
bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DEFAULT);
int iStartPos = 0;
while (cont)
{
wxString file = in_folder + wxFILE_SEP_PATH + filename;
iPos = file.Find(in_folder_old);
if(wxString::npos != iPos )
{
iStartPos = in_folder_old.length();
file_and_folder_short_name = file.substr(iStartPos);
}
const char* file_char = file;
if (wxFileExists(file))
{
if((_access(file, 2)) != -1)
{
file_and_folder_short_name = file_and_folder_short_name.substr(1);
ch_filename = new TCHAR[file_and_folder_short_name.length()];
lstrcpy(ch_filename, file_and_folder_short_name);
//File to Zip
ch_fullpath = new TCHAR[file.length()];
lstrcpy(ch_fullpath, file);
ZipAdd(newZipFile, ch_filename, ch_fullpath); //将文件添加到zip文件中
}
}
else
{
file_and_folder_short_name =file_and_folder_short_name.substr(1)+"/";
ch_folder = new TCHAR[file_and_folder_short_name.length()];
lstrcpy(ch_folder, file_and_folder_short_name);
ZipAdd(newZipFile, ch_folder, NULL); //建立一个文件夹
ZIP_Folder(file,in_folder_old,out_filename,newZipFile);
}
cont = dir.GetNext(&filename);
}
return ;
}
完
使用的方法:
/*
HZIP newZipFile = CreateZip(full_filepath_,0);
ZIP_Folder(str_path, str_path, full_filepath_,newZipFile);
CloseZip(newZipFile); //关闭zip文件
*/
|
|