Sample code for 30+ languages & platforms
Zig

Demonstrate Directory Path Functions

Demonstrates the path functions GetDirectoryName, GetExtension, GetFileName, and GetFileNameWithoutExtension.

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();

    const fac = try chilkat.FileAccess.init();
    defer fac.deinit();

    // Note: Chilkat accepts either forward slash or backslash chars as directory separators..
    std.debug.print("{s}\n", .{try fac.getDirectoryName(alloc, "/MyDir/MySubDir/myfile.ext")});
    std.debug.print("{s}\n", .{try fac.getDirectoryName(alloc, "/MyDir/MySubDir")});
    std.debug.print("{s}\n", .{try fac.getDirectoryName(alloc, "/MyDir/")});
    std.debug.print("{s}\n", .{try fac.getDirectoryName(alloc, "/MyDir")});
    std.debug.print("{s}\n", .{try fac.getDirectoryName(alloc, "/")});

    std.debug.print("{s}\n", .{try fac.getExtension(alloc, "C:/mydir.old/myfile.ext")});
    std.debug.print("{s}\n", .{try fac.getExtension(alloc, "C:/mydir.old/")});

    std.debug.print("{s}\n", .{try fac.getFileName(alloc, "C:/mydir/myfile.ext")});
    std.debug.print("{s}\n", .{try fac.getFileName(alloc, "C:/mydir/")});

    std.debug.print("{s}\n", .{try fac.getFileNameWithoutExtension(alloc, "C:/mydir/myfile.ext")});
    std.debug.print("{s}\n", .{try fac.getFileNameWithoutExtension(alloc, "C:/mydir/")});

    std.debug.print("---\n", .{});
}