TCHAR zipname[] = "C:\\bcel";
    TCHAR zipfile [FILENAME_MAX];
    sprintf(zipfile, "%s.zip", zipname);    
    if(Exists(zipfile))
    {
        int num = 2;
        while(Exists(zipfile))
            sprintf(zipfile, "%s%d.zip", zipname, num++);       
    }
    HZIP hz = CreateZip(zipfile,0);
    deque<string>folderList;
    TCHAR folderpath[MAX_PATH]="D:\\Desktop\\Desktop\\bcel-5.2";
    folderList.push_back(string(folderpath));
    while(folderList.size()>0)
    {
        WIN32_FIND_DATA finddata;
        string pathfile=folderList.front();
        string subdir=pathfile;
        pathfile.append("\\*.*");
        HANDLE handleFind = FindFirstFile(pathfile.c_str(),&finddata); //FindFirstFile
        folderList.pop_front();
        if(handleFind != INVALID_HANDLE_VALUE)
        {
            do
            {
                if(finddata.cFileName[0]=='.')
                    continue;
                else if(finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                {
                    string subpath=subdir;
                    subpath.append("\\");
                    subpath.append(finddata.cFileName);
                    folderList.push_back(subpath);
                }
                else
                {
                    string filename=subdir;
                    filename.append("\\");
                    filename.append(finddata.cFileName);
                    string zipdir = filename.substr(strlen(folderpath)+1);
                    ZipAdd(hz,zipdir.c_str(),filename.c_str());
                }
            }while(FindNextFile(handleFind,&finddata));
            FindClose(handleFind);
        }
    }
    CloseZip(hz);
posted on 2017-07-10 16:03  baraka  阅读(2235)  评论(0编辑  收藏  举报