我正在尝试使用 libzip 库创建 zip 文件。
list<string> ListOfFiles;
ListOfFiles.push_back("file1");
ListOfFiles.push_back("file2");
ListOfFiles.push_back("file3");
...
createZip(const char* destination)
{
int err;
zip *archive = zip_open(destination, ZIP_CREATE, &err);
cout << "1. " << zip_strerror(archive) << endl;
for (list<string>::iterator iter = ListOfFiles.begin(), end = ListOfFiles.end(); iter != end; iter++)
{
zip_source *source = zip_source_file(archive,iter->c_str(),0,0);
cout << "2. " << zip_strerror(archive) << endl;
index = zip_file_add(archive, iter->c_str(), source, ZIP_FL_OVERWRITE);
cout << "3. " << zip_strerror(archive) << endl;
}
zip_close(archive);
cout << "4. " << zip_strerror(archive) << endl;
}
输出:
没有错误
没有错误
无效的论点 ...
读取错误:没有这样的文件或目录
当我尝试创建 zip 时,尝试将文件添加到 zip 后,错误值返回“无效参数”。