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
623 stars 113 forks source link

[Feature Request]: extract non-matching files #61

Closed tflinkow closed 11 months ago

tflinkow commented 2 years ago

Feature description

I use the following code to extract all files from a .7z that are not .sql files.

bit7z::Bit7zLibrary library { L"7z.dll" };
bit7z::BitExtractor extractor { library, bit7z::BitFormat::SevenZip };

extractor.extractMatching(downloadedFile, L"!*.sql", extractionPath);

Since the filter *.sql can be used to only extract .sql files, I tried using !*.sql to exclude them from the extraction, similar to the 7z.exe -x switch.


However, this filter throws an exception:

mErrorCode = 0x0000006e : The system cannot open the device or file specified.


Am I doing something wrong? Is there any way I can achieve my goal of not extracting .sql files, optimally without having to explicitly loop over all items and checking myself?

Additional context

No response

Code of Conduct

rikyoz commented 2 years ago

Hi! First of all, thank you for sponsoring me and this project!

Since the filter .sql can be used to only extract .sql files, I tried using !.sql to exclude them from the extraction, similar to the 7z.exe -x switch.

Yeah, the current bit7z's wildcard matching system is pretty basic, and it doesn't support "negative" matching, as 7-zip does. It only supports * and ? wildcards. I'm sorry, I think I should have implemented it before, and I'll probably do it in a future version.

Is there any way I can achieve my goal of not extracting .sql files, optimally without having to explicitly loop over all items and checking myself?

It should be possible to achieve it with the current bit7z version by using regular expression matching, e.g.:

extractor.extractMatchingRegex(downloadedFile, L"^(?!.*\.sql$).*$", extractionPath);

Please note that, by default, bit7z is compiled without regex support. For enabling it, you should compile the library by defining the flag BIT7Z_REGEX_MATCHING (e.g., using CMake, cmake [...] -DBIT7Z_REGEX_MATCHING=ON). You will also need to define the same flag before including the bit7z header files.

rikyoz commented 11 months ago

Implemented in v4.0.0.