本文主要是介绍[C++ zip] 如何压缩一个文件夹?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/*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 Zipch_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文件
*/
完
这篇关于[C++ zip] 如何压缩一个文件夹?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!