Search code examples
c++ubuntuziplibzip

Does LIBZIP provides a way to check if zip_file is a DIRECTORY?


I'm using a pretty old version of libzip (0.10.1-1.2) due compatibility matters.

Usually we do check file type (symbolic link, dir, file, etc) by its stat result. Analogously, on libzip we zip_stat, but its structure do not contain anything like ST_MOD from a filesystem STAT.

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 */
};

Is there a way to check whether entry is a DIR or not?


Solution

  • Yes. Check whether the final character of name is '/'. Only directories end in '/'.

    Sources: