Go to file
2024-01-03 08:54:10 +01:00
.github/workflows up zig setup for CI 2021-01-27 08:48:46 +01:00
.gitattributes Windows ❤️ 2020-08-05 18:57:31 +02:00
.gitignore Starts to implement windows GUID part. 2020-05-19 00:50:28 +02:00
build.zig Update build.zig 2024-01-03 08:54:10 +01:00
gyro.zzz add gyro packaging 2021-01-27 08:48:46 +01:00
known-folders.zig shell32 and ole32 removed from std 2023-11-24 13:07:39 -05:00
LICENSE Initial commit 2020-05-18 23:48:44 +02:00
README.md fix API in readme 2023-07-09 10:15:33 +02:00
RESOURCES.md split up readme 2020-05-28 20:58:22 +02:00
zig.mod add native support for zigmod package manager 2021-02-15 10:48:56 +01:00

Zig Known Folders Project

Design Goals

  • Minimal API surface
  • Provide the user with an option to either obtain a directory handle or a path name
  • Keep to folders that are available on all operating systems

API

pub const KnownFolder = enum {
    home,
    documents,
    pictures,
    music,
    videos,
    desktop,
    downloads,
    public,
    fonts,
    app_menu,
    cache,
    roaming_configuration,
    local_configuration,
    global_configuration,
    data,
    runtime,
    executable_dir,
};

pub const Error = error{ ParseError, OutOfMemory };

pub const KnownFolderConfig = struct {
    xdg_force_default: bool = false,
    xdg_on_mac: bool = false,
};

/// Returns a directory handle, or, if the folder does not exist, `null`.
pub fn open(allocator: std.mem.Allocator, folder: KnownFolder, args: std.fs.Dir.OpenDirOptions) (std.fs.Dir.OpenError || Error)!?std.fs.Dir;

/// Returns the path to the folder or, if the folder does not exist, `null`.
pub fn getPath(allocator: std.mem.Allocator, folder: KnownFolder) Error!?[]const u8;

Configuration

In your root file, add something like this to configure known-folders:

pub const known_folders_config = .{
    .xdg_on_mac = true,
}