Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ziglibs/known-folders
Provides access to well-known folders across several operating systems
https://github.com/ziglibs/known-folders
zig zig-library zig-package
Last synced: 3 days ago
JSON representation
Provides access to well-known folders across several operating systems
- Host: GitHub
- URL: https://github.com/ziglibs/known-folders
- Owner: ziglibs
- License: mit
- Created: 2020-05-18T21:48:43.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-07-31T15:21:03.000Z (4 months ago)
- Last Synced: 2024-12-02T00:05:14.825Z (10 days ago)
- Topics: zig, zig-library, zig-package
- Language: Zig
- Size: 108 KB
- Stars: 234
- Watchers: 9
- Forks: 22
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-game-engine-dev - Known Folders - Provides access to well-known folders across several operating systems. (Libraries / Zig)
- awesome-zig - ziglibs/known-folders - known folders across several operating systems. (File format processing / Utility)
- awesome-zig - known-folders🗒️Provides access to well-known folders across several operating systems
README
# 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
```zig
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.OpenOptions) (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;
```## Installation
Initialize a `zig build` project if you haven't already.
```bash
zig init
```Add the `known-folders` package to your `build.zig.zon`.
```bash
zig fetch --save git+https://github.com/ziglibs/known-folders.git
```You can then import `known-folders` in your `build.zig` with:
```zig
const known_folders = b.dependency("known-folders", .{}).module("known-folders");
const exe = b.addExecutable(...);
// This adds the known-folders module to the executable which can then be imported with `@import("known-folders")`
exe.root_module.addImport("known-folders", known_folders);
```## Configuration
In your root file, add something like this to configure known-folders:
```zig
pub const known_folders_config = .{
.xdg_on_mac = true,
}
```