我有一个 tar 文件,我想使用 libarchive 将其提取到特定目录。如何将 libarchive 提取到我想要的任何目录?目前,它总是 提取到我程序的工作目录中。我看了this answer但这一切所做的只是更改存档中存档条目的位置,即它仍然提取到我的程序的工作目录中,只是在不同的子目录中。
最佳答案
我接下来通过以下方式解决了这个问题: (在调用“archive_write_header”函数之前插入此代码)
const char* currentFile = archive_entry_pathname(archiveEntry);
const std::string fullOutputPath = destination + currentFile;
archive_entry_set_pathname(archiveEntry, fullOutputPath.c_str());
其中 destination
是输出路径。
并且有效。
关于c++ - libarchive - 提取到指定目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8384266/