由于兼容性问题,我使用的是相当旧的 libzip 版本 (0.10.1-1.2)。
通常我们通过统计结果来检查文件类型(符号链接(symbolic link)、目录、文件等)。类似地,在 libzip 上我们 zip_stat,但它的结构不包含文件系统 STAT 中的 ST_MOD 之类的任何内容。
struct zip_stat {
zip_uint64_t valid; /* which fields have valid values */
const char *name; /* name of the file */
zip_uint64_t index; /* index within archive */
zip_uint64_t size; /* size of file (uncompressed) */
zip_uint64_t comp_size; /* size of file (compressed) */
time_t mtime; /* modification time */
zip_uint32_t crc; /* crc of file data */
zip_uint16_t comp_method; /* compression method used */
zip_uint16_t encryption_method; /* encryption method used */
zip_uint32_t flags; /* reserved for future use */
};
有没有办法检查条目是否是DIR?
最佳答案
是的。检查name
的最后一个字符是否为'/'
。只有目录以 '/'
结尾。
来源:
- https://libzip.org/documentation/zip_file_rename.html#ZIP_ER_INVAL
- libzip 源代码中的许多地方都使用了这个规则。搜索
'/'
以查看它们。
关于c++ - LIBZIP 是否提供了一种方法来检查 zip_file 是否是目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56480947/