首页 文章

使用zlib解压缩而不使用SetCurrentDirectory

提问于
浏览
0

我正在使用zlib来解压缩zip文件列表 . 这是一种简单的方法 . 但 SetCurrentDirectory 函数调用会影响我的其他线程 . 有没有办法使用zlib解压缩到特定的目录 .

SetCurrentDirectory("c:\\docs\\stuff");
HZIP hz = OpenZip("c:\\stuff.zip",0);
ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;
for (int i=0; i<numitems; i++)
{ GetZipItem(hz,i,&ze);
   UnzipItem(hz,i,ze.name);
 }
 CloseZip(hz);

2 回答

  • 1

    你有一个包装器,可以轻松使用zlib库 . 您已将问题标记为C,您正在使用c的包装器,同时您正在使用利用此包装器的全局帮助程序API .

    我建议您直接使用TUnzip包装器(请参阅如何实现 UnzipItemInternal 作为示例) . TUnzip类有一个很好的方法,允许设置基目录 ZRESULT TUnzip::SetUnzipBaseDir(const TCHAR *dir) . 调用它来设置目录

  • 1

    找到了解决方案 .

    void unZipPackage(std::wstring zip_file,std::wstring dest_dir){ 
    
        HZIP hz = OpenZip(zip_file.c_str(),0);  
        ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;
        for (int i=0; i<numitems; i++)
        { 
            GetZipItem(hz,i,&ze);               
            wchar_t dest[MAX_PATH];
            swprintf(dest,MAX_PATH,L"%s\\%s",dest_dir.c_str(),ze.name);     
            UnzipItem(hz,i,dest);       
        }   
        CloseZip(hz);
    }
    

相关问题