使用 XZIP 打开 C++ 中的 zip 文件

Opening a zip file in C++ with XZIP

本文关键字:zip 文件 中的 C++ XZIP 打开 使用      更新时间:2023-10-16

在我当前的项目中,我必须转到某个用户输入的目录,打开该目录并读取该目录中以W开头的所有zip文件。我正在尝试使用 XZIP 库打开 ZIP 文件,但我肯定做错了什么。我很困惑是使用 UnzipItem 还是 Openzip 来打开 zip 文件并解析其内容。(每个zip文件都包含一些.jpg文件,我必须将这些文件复制到另一个位置,但这是项目的第二部分)

我真的很感激一些帮助,谢谢:)

这是我的代码-

#include "StdAfx.h"
#include "srcXZip.h"
#include "srcXUnzip.h"
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include "srcdirent.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <windows.h>

int main()
{
  std::ifstream fin;
  std::string dir, filepath;
  int num;
  DIR *dp;
  struct dirent *dirp;
  struct stat filestat;
  std::string filename;
  std::string userInput;
  std::cout << " Input dir to get files from : ";
  getline( std::cin, dir );  // gets everything the user 
  dp = opendir( dir.c_str() );
  if (dp == NULL)
    {
        std::cout << "Error opening " << dir << std::endl;
    }
  char test[2];
  while ((dirp = readdir( dp )) != NULL)
    {  // printf(" inside the directory ");
        filepath = dir+"/" + dirp->d_name;
        filename =dirp->d_name;
        test[0]=filename[0];
        test[1]='';
        if ( test[0]=='W')
        {   HZIP* z;
            DWORD File_name = std::strtoul(filename.c_str(), NULL, 16);
            OpenZip(z,0,File_name);

        }
  }
    return 0;
}

从文档中,我会说您首先需要调用OpenZip以获取句柄,并且使用该句柄调用UzipItem您从FindZipItem获得的项目 ID .

我所拥有的只是文档:

标志 - 表示用法,见下文; 对于文件,这将ZIP_FILENAME

所以我猜是这样的:auto handle = OpenZip("file.zip", 0, ZIP_FILENAME);