Sample code for 30+ languages & platforms
Zig Requires Chilkat v11.0.0+

List Files in a .zip

See more Zip Examples

How to list files within a .zip

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const zip = try chilkat.Zip.init();
    defer zip.deinit();

    zip.openZip("a.zip") catch {
        std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
        return;
    };

    // Get the number of files and directories in the .zip
    const n = zip.getNumEntries();

    const entry = try chilkat.ZipEntry.init();
    defer entry.deinit();

    var i: i32 = 0;

    while (i < n) {
        zip.entryAt(i, entry) catch {};
        if (!entry.getIsDirectory()) {
            // (the filename may include a path)
            std.debug.print("{s}\n", .{try entry.getFileName(alloc)});
        }

        i = i + 1;
    }
}