zoukankan      html  css  js  c++  java
  • C++调用windowsAPI实现目录zip压缩

     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);
  • 相关阅读:
    《构建之法》第四章的感悟
    单复利软件单元测试
    实验一 操作系统模仿cmd
    <构建之法>第一二三章感悟
    近期工作量统计
    复利计算3.0
    复利运算
    单利运算1
    复利计算6.0
    汉堡包
  • 原文地址:https://www.cnblogs.com/daochong/p/7146283.html
Copyright © 2011-2022 走看看