Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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-


C++
#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;
}
Posted
Updated 5-Nov-13 12:16pm
v4
Comments
Sergey Alexandrovich Kryukov 5-Nov-13 18:17pm    
Changed "pre lang" attribute to "C++", to color/format code properly.
—SA

1 solution

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[^]
 
Share this answer
 
v2
Comments
Member 10368093 6-Nov-13 10:06am    
Thanks for the response, I tried the code from that article,
HZIP hz = OpenZip(filepath.c_str(),0); I have filepath as a string, so when I use it in OpenZip I get the error "argument of type "const char" is incompatible with parameter of type "void *", I dont know how to get past that"
Secondly when i use this line UnzipItem(hz,zi,ze.name);
I get the error " too few arguments in function call", I tried putting in Nulls but that didnt help.

Any Ideas?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900