使用XZIP在C ++中打开一个zip文件 [英] Opening a zip file in C++ with XZIP
问题描述
在我当前的项目中,我必须转到某个用户输入的目录,打开该目录并读取该目录中所有以W开头的zip文件.我试图使用XZIP库打开ZIP文件,但是我肯定做错了什么.我对使用UnzipItem还是Openzip打开zip文件并解析其内容感到困惑. (每个zip文件都包含一些.jpg文件,我必须将这些文件复制到另一个位置,但这是项目的第二部分)
另一个主要问题是我给Openzip打电话的方式.这不是调用函数的正确方法,我想就我的代码了解调用它的正确方法.
我真的很感谢您的帮助,谢谢:)
这是我的代码-
In my current project, I have to go to a certain user inputted directory, open that directory and read all the zip files in that directory which begin with W. I am trying to use the XZIP library for opening the ZIP files, but I am certainly doing something very wrong. I am confused whether to use UnzipItem or Openzip to open the zip file and parse through its contents. (The zip files each contain some .jpg files and I have to copy those files into another location, but that''s the second part of the project)
Another major issue is the way I am calling Openzip. this is not the correct way to call the function, I would like to know the correct way to call it with respect to my code.
I would really appreciate some help, Thanks :)
Here is my code-
#include "StdAfx.h"
#include "src\XZip.h"
#include "src\XUnzip.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]='\0';
if ( test[0]=='W')
{ HZIP* z;
DWORD File_name = std::strtoul(filename.c_str(), NULL, 16);
OpenZip(z,0,File_name);
}
}
return 0;
}
推荐答案
看看这篇文章.我认为这与他使用的库相同,他非常简洁地说明了如何使用它. (我认为他们甚至为此包装)
Zip Utils-干净,优雅,简单,C ++/Win32 [^ ]
Have a look at this article. I think it''s the same library he uses and he explains very neatly how to work with it. (I think theirs even a wrapper for it)
Zip Utils - clean, elegant, simple, C++/Win32[^]
这篇关于使用XZIP在C ++中打开一个zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!