Search code examples
c++zipunzip

Move all the files from a ZIP archive to another


I am searching for a few days a library that just has to move all the files in a ZIP archive, to another in C++. I found libzip, but it it is better just for some files that you know the names. I don't care of the steps between the archive A and the archive B, as long as it doesn't take too much time. (and if possible, it will remove the files in its temporary folder). And I prefer a portable library.

Thanks you!


Solution

  • Libzip is probably the best bet.

    You can use zip_get_num_entries to get the number of files in an archive, then use zip_get_name to get the file-name of a specific file. Use zip_fopen_index to open a file inside the archive, zip_fread to read the file (and save either to disk or to another zip archive) and when done zip_fclose to close the file. If you want to remove the file from the archive use zip_delete.

    Continue to do this in a loop for all files, starting with the highest index down to index zero.


    As for libzip on Windows, see e.g. this answer (or if it doesn't work this one).