Overview
Features
Download
Documentation
Community
Add-Ons & Services

enumerate all files and directories in a zip

A general discussion forum.

enumerate all files and directories in a zip

Postby thready » 02 Mar 2010, 17:24

Hi Poco Experts,

How can I enumerate a zip for all its files and directories? Do I use ZipArchive for this? I did see in the zip user manual the following code to look up one file:
std::ifstream inp("test.zip", std::ios::binary);
poco_assert (inp);
ZipArchive arch(inp);
ZipArchive::FileHeaders::const_iterator it = arch.findHeader("data/hello.txt");
poco_assert (it != arch.headerEnd());
ZipInputStream zipin (inp, it->second);
std::ostringstream out(std::ios::binary);
Poco::StreamCopier::copyStream(zipin, out);

However, I need to know how to do the traversal of all directories and files.

Thank you!
Mike
thready
 
Posts: 39
Joined: 20 Jan 2010, 17:20

Re: enumerate all files and directories in a zip

Postby guenter » 09 Mar 2010, 19:12

Here's some code fragment to list all files and directories in a Zip file:

Code: Select all
   std::vector<std::string>& files;
   ZipArchive::FileHeaders::const_iterator it(_pArchive->headerBegin());
   ZipArchive::FileHeaders::const_iterator end(_pArchive->headerEnd());
   std::set<std::string> fileSet;
   while (it != end)
   {
      files.push_back(it->first);
      ++it;
   }
guenter
 
Posts: 1121
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron