简体   繁体   English

将所有文件从ZIP存档移动到另一个

[英]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++. 我正在搜索几天的库,该库只需要将ZIP存档中的所有文件移动到C ++中的另一个文件中即可。 I found libzip, but it it is better just for some files that you know the names. 我找到了libzip,但是最好只知道一些文件名。 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. 我不关心档案A和档案B之间的步骤,只要不花费太多时间即可。 (and if possible, it will remove the files in its temporary folder). (如果可能,它将删除其临时文件夹中的文件)。 And I prefer a portable library. 而且我更喜欢一个可移植的库。

Thanks you! 谢谢!

Libzip is probably the best bet. Libzip可能是最好的选择。

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. 您可以使用zip_get_num_entries获取存档中的文件数,然后使用zip_get_name获取特定文件的文件名。 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. 使用zip_fopen_index打开存档中的文件,使用zip_fread读取文件(并将其保存到磁盘或另一个zip存档中),完成后使用zip_fclose关闭文件。 If you want to remove the file from the archive use zip_delete . 如果要从存档中删除文件,请使用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 eg this answer (or if it doesn't work this one ). 至于在Windows libzip,例如见这个答案 (或者,如果它不工作这一项 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM