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

Generate a new folder in the compressed file,and compress the file to the new folder. #41

Open zhenhxiaobin0210 opened 4 years ago

zhenhxiaobin0210 commented 4 years ago

question: (1) Generate a new folder in the compressed file;

(2) Compress the file to the (1) folder.

zhenhxiaobin0210 commented 4 years ago

Can you give me some examples, thank you

rikyoz commented 4 years ago

Hi! Sorry for the late reply!

question: (1) Generate a new folder in the compressed file;

Generating an empty folder inside a compressed file is not possible, at the moment.

(2) Compress the file to the (1) folder.

However, you can achieve your goal by using the method

void BitCompressor::compress( const map< wstring, wstring >& in_paths, const wstring& out_file ) const;

which allows to compress files while giving them a new alias. In particular, you could use it as follows:

std::map< std::wstring, std::wstring > file_map = {
    { L"path/to/file.ext", L"new_folder/file.ext" }
};
compressor.compress( file_map, out_file );

In this way, the compressed file will appear inside a folder called new_folder in the output archive.

zhenhxiaobin0210 commented 4 years ago

Thank you very much for your reply! Now I want to update some of the files in the compressed file. If there is already a“ xx.dat ”How do I overwrite this file. If I use this function“ compressor.setUpdateMode (true) "will generate two files with the same name in the compressed file“ xx.dat " But actually I want to overwrite the original file with the same name. thank you!