rikyoz / bit7z

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.
https://rikyoz.github.io/bit7z
Mozilla Public License 2.0
627 stars 114 forks source link

Hope to custom the directory system in the zip file #8

Closed EruditePig closed 6 years ago

EruditePig commented 7 years ago

I used a zip.h and zip.cpp before. In its API, I can custom the directory system in the zip file.Here is its sample code.

HZIP hz = CreateZip("c:\\simple1.zip",0);
ZipAdd(hz,"1\\znsimple.bmp", "c:\\simple.bmp");
ZipAdd(hz,"znsimple.txt", "c:\\simple.txt");
CloseZip(hz);

and I can get the directory like this in the zip file. -1 |--zmsimple.hpp -znsimple.txt

If i compress file in the bit7z like this

std::vector<std::wstring> files = { L"1\\file1.jpg", L"file2.pdf" };
compressor.compressFiles(files, L"output_archive.zip");

the file1.jpg and the file2.pdf just lay in the zip file, I cann't specify the directory system in the zip file.

Thank you!

rikyoz commented 7 years ago

Unfortunately that compressFiles method doesn't retain the directory structure by design. Actually, I don't like how bit7z handles files, to be honest, and I planned to improve it as soon as I can, probably rewriting it from scratch. Anyway, a method which retains the directory structure is the following:

void BitCompressor::compressFiles( const wstring& in_dir, const wstring& out_archive, 
                                   const wstring& filter = L"*", bool recursive = true ) const;

As you can see, it doesn't have the same flexibility of your requirements: first of all, you have to specify the directory in_dir containing the files to be compressed (instead of a vector of file paths, as in the other compressFiles method); then, in order to compress only the files you want, you must specify a file filter, a string which can include wildcards (e.g. simple*.* will select all files starting with the string simple). Moreover, the archive will contain a folder with the name of the directory in_dir, hence it will have the structure:

dir_name
|--1\\file1.jpg
|--file2.jpg

I don't know if you can adapt it to your requirements. I hope to improve the flexibility of the API in future!

EruditePig commented 7 years ago

Hi,

I noticed that API last night, and it doesn't fit my requirements.

I am coding a program to archive the files for the result files of a structure analysis software. It has a lot of filter that maybe only regex can handle. So i give up that API.

I am looking forward to your improvement!

Thank you!