【问题标题】:libzip function to find index of filename doesn't work c++查找文件名索引的libzip函数不起作用c ++
【发布时间】:2015-06-09 16:47:51
【问题描述】:

我今天开始学习 libzip,一切都很顺利,只是我无法让 zip_name_locate 工作,而且我找不到任何解释它的教程/示例/文档(文档可以,但我不能让它工作)。 Documentation 1Documentation 2(我无法让其中任何一个工作,文档 2 页面也有一些显然没有在我的范围内声明的枚举)

首先,我的 zip 存档可以正确打开,因为我可以在其中替换和添加文件。我有显示索引路径的终端输出(来自 zip_get_name 函数)。

存档中的文件数:3
假人/
假人/dummy1/
dummy/dummy1/dummytxt

无论我试图找到其中哪一个的索引,我总是得到“dummy/”的索引,即 0,我也尝试过所有不同的枚举 (ZIP_FL_COMPRESSED、ZIP_FL_ENCRYPTED、ZIP_FL_NOCASE、ZIP_FL_NODIR、ZIP_FL_RECOMPRESS、ZIP_FL_UNCHANGED 和 0)。

(这个“dummy/dummy1/”返回0,根据zip_get_name是“dummy/”)

如果有任何帮助,我将不胜感激。

【问题讨论】:

    标签: c++ zip archive unzip libzip


    【解决方案1】:

    好的,所以我找到了使用 zip_stat 结构的“解决方法”。

    struct zip_stat stat;
    zip_stat_init(&stat);
    zip_stat(zipPointer, "dummy/dummy1/dummytxt", 0, &stat);
    std::cout << "name= " <<stat.name << ", index= " << stat.index << std::endl;
    

    这将打印“name= dummy/dummy1/dummytxt, index= 2”。您也可以使用“zip_stat_index”来通过索引构建 zip_stat 结构。 在这里,您有一些有关 zip_stat 结构的文档以及您可以使用它的用途,它似乎非常有用。 Documentation1, Documentation2, Documentation3.

    哦,如果你有问题,调试器说 stat 没有在这个范围内声明,请确保你这样写:struct zip_stat stat;。您可能错过了声明前面的结构。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-13
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      • 1970-01-01
      • 1970-01-01
      • 2017-10-05
      • 2016-05-18
      相关资源
      最近更新 更多