Returns user-specific, platform-specific directory paths across Linux, macOS, and Windows.
Dependencies
test "dir delegates to named helpers" {
assert_eq(@dirs.dir("cache"), @dirs.cache_dir())
assert_eq(@dirs.dir("config"), @dirs.config_dir())
}fn audio_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_MUSIC_DIR, then HOME/Music |
| macOS | HOME/Music |
| Windows | USERPROFILE/Music, then HOMEDRIVE + HOMEPATH + Music |
fn cache_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_CACHE_HOME, then HOME/.cache |
| macOS | HOME/Library/Caches |
| Windows | LOCALAPPDATA |
fn config_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_CONFIG_HOME, then HOME/.config |
| macOS | HOME/Library/Preferences |
| Windows | APPDATA |
fn data_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_DATA_HOME, then HOME/.local/share |
| macOS | HOME/Library/Application Support |
| Windows | APPDATA |
fn data_local_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | Same as data_dir() |
| macOS | Same as data_dir() |
| Windows | LOCALAPPDATA |
fn desktop_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_DESKTOP_DIR, then HOME/Desktop |
| macOS | HOME/Desktop |
| Windows | USERPROFILE/Desktop, then HOMEDRIVE + HOMEPATH + Desktop |
fn dir(kind : String) -> String?| Name | Meaning |
|---|---|
| "home" | The current user's home directory |
| "cache" | A directory for cached, disposable data |
| "config" | A directory for user-specific configuration files |
| "executable" | A directory for user-specific executables |
| "data" | A directory for user-specific shared application data |
| "data_local" | A directory for user-specific machine-local application data |
| "audio" | The user's music directory |
| "desktop" | The user's desktop directory |
| "document" | The user's documents directory |
| "download" | The user's downloads directory |
| "font" | The user's font directory |
| "picture" | The user's pictures directory |
| "public" | A public shared directory |
| "template" | The user's templates directory |
| "tmp" | The preferred temporary directory |
| "video" | The user's videos directory |
test "dir agrees with dedicated helpers" {
assert_true(@dirs.dir("cache") == @dirs.cache_dir())
assert_true(@dirs.dir("tmp") == @dirs.tmp_dir())
assert_true(@dirs.dir("unsupported") == None)
}fn document_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_DOCUMENTS_DIR, then HOME/Documents |
| macOS | HOME/Documents |
| Windows | USERPROFILE/Documents, then HOMEDRIVE + HOMEPATH + Documents |
fn download_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_DOWNLOAD_DIR, then HOME/Downloads |
| macOS | HOME/Downloads |
| Windows | USERPROFILE/Downloads, then HOMEDRIVE + HOMEPATH + Downloads |
fn executable_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_BIN_HOME, then XDG_DATA_HOME/../bin, then HOME/.local/bin |
| macOS | Not defined |
| Windows | Not defined |
fn font_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_DATA_HOME/fonts, then HOME/.local/share/fonts |
| macOS | HOME/Library/Fonts |
| Windows | Not defined |
fn home_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | HOME |
| macOS | HOME |
| Windows | USERPROFILE, then HOMEDRIVE + HOMEPATH |
fn picture_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_PICTURES_DIR, then HOME/Pictures |
| macOS | HOME/Pictures |
| Windows | USERPROFILE/Pictures, then HOMEDRIVE + HOMEPATH + Pictures |
fn public_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_PUBLICSHARE_DIR, then HOME/Public |
| macOS | HOME/Public |
| Windows | PUBLIC, then SYSTEMDRIVE\\Users\\Public |
fn template_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_TEMPLATES_DIR, then HOME/Templates |
| macOS | Not defined |
| Windows | APPDATA/Microsoft/Windows/Templates |
fn tmp_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_RUNTIME_DIR/tmp, then TMPDIR, TEMP, TMP, then /var/tmp |
| macOS | TMPDIR |
| Windows | TMP, then TEMP |
fn video_dir() -> String?| Platform | Resolution order |
|---|---|
| Linux | XDG_VIDEOS_DIR, then HOME/Videos |
| macOS | HOME/Movies |
| Windows | USERPROFILE/Videos, then HOMEDRIVE + HOMEPATH + Videos |
Returns user-specific, platform-specific directory paths across Linux, macOS, and Windows.
Dependencies