Sample code for 30+ languages & platforms
Zig

Create Zip Excluding Files Matching Patterns

See more Zip Examples

How to create a .zip archive excluding (skipping) files that match a set of wildcarded patterns.

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.newZip("test.zip") catch {
        std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
        return;
    };

    // Create a string array object with our set of filename patterns
    // to be excluded:
    const sa = try chilkat.StringArray.init();
    defer sa.deinit();
    try sa.append("*.bak");
    try sa.append("*.tmp");

    // Tell the zip object to use these exclusions:
    zip.setExclusions(sa);

    // Append a directory tree.  The AppendFiles does
    // not read the file contents or append them to the zip
    // object in memory.  It simply appends references
    // to the files so that when WriteZip (or WriteZipAndClose,
    // or WriteExe, etc.) is called, the files are compressed
    // and encrypted.
    const recurse = true;
    try zip.appendFiles("/temp/a/*", recurse);

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

    std.debug.print("Zip Created!\n", .{});
}