简体   繁体   English

用于查找文件名索引的libzip函数不起作用C ++

[英]libzip function to find index of filename doesn't work c++

I started learning libzip today everything is going great, it's just that I can't get the zip_name_locate to work and I can't find any tutorials/examples/documentation that explains it(well the documentation does but I can't get it to work). 我今天开始学习libzip,一切进展顺利,只是我无法使zip_name_locate正常工作,也找不到任何解释它的教程/示例/文档(文档虽然很好,但我无法理解它)工作)。 Documentation 1 , Documentation 2 ( I can't get any of these to work, the Documentation 2 page also has some enums that apparently haven't been declared in my scope) 文档1文档2 (我无法使用其中的任何一个,“文档2”页面上也有一些枚举,显然没有在我的范围内声明)

So first, my zip archive opens correctly as I can replace and add files to it. 因此,首先,我的zip存档可以正确打开,因为我可以对其进行替换和添加文件。 I've got terminal output that shows the paths of the indexes (from the zip_get_name function). 我有显示索引路径的终端输出(来自zip_get_name函数)。

Number of files in archive: 3 存档文件数:3
dummy/ 假/
dummy/dummy1/ 虚拟/ dummy1 /
dummy/dummy1/dummytxt 虚设/ dummy1 / dummytxt

No matter which one of these I try to find the index of, I always get the index of "dummy/" which is 0, I've also tried with all different enums (ZIP_FL_COMPRESSED, ZIP_FL_ENCRYPTED, ZIP_FL_NOCASE, ZIP_FL_NODIR, ZIP_FL_RECOMPRESS, ZIP_FL_UNCHANGED and 0). 无论我尝试查找其中哪一个索引,我总会得到“ dummy /”的索引,该索引为0,我也尝试了所有不同的枚举(ZIP_FL_COMPRESSED,ZIP_FL_ENCRYPTED,ZIP_FL_NOCASE,ZIP_FL_NODIR,ZIP_FL_RECOMPRESS,ZIP_FL_UNCHANGED和0)。

(This "dummy/dummy1/" returns 0, which according to zip_get_name is "dummy/") (此“ dummy / dummy1 /”返回0,根据zip_get_name的值为“ dummy /”)

I would be very grateful for any help. 我将非常感谢您的帮助。

Alright so I found a "workaround" using the zip_stat structure. 好吧,所以我找到了使用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;

This would print "name= dummy/dummy1/dummytxt, index= 2". 这将显示“名称=虚拟/ dummy1 / dummytxt,索引= 2”。 You can also use "zip_stat_index" to build the zip_stat structure by the index instead. 您也可以使用“ zip_stat_index”代替通过索引来构建zip_stat结构。 Here you have some documentation for the zip_stat struct and what you can use it for, it seems very useful. 在这里,您有一些有关zip_stat结构的文档及其用途,它似乎非常有用。 Documentation1 , Documentation2 , Documentation3 . 文档1文档2文档3

Oh and also if you have problems that the debugger says that stat has not been declared in this scope make sure you write it like this: struct zip_stat stat; 哦,如果调试器说未在此范围内声明stat时遇到问题,请确保按以下方式编写: struct zip_stat stat; . You've probably missed the struct in front of the declaration. 您可能已经错过了声明前面的结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM