dirs

    Returns user-specific, platform-specific directory paths across Linux, macOS, and Windows.

    moonbit
    directories
    xdg
    windows
    macos
    linux
    Download zip
    Author
    Version
    0.1.3
    License
    MIT
    Last updated
    8 days ago
    Downloads
    41

    Dependencies

    #justjavac/dirs

    Directory helpers for Linux, macOS, and Windows.

    #Example

    test "dir delegates to named helpers" {
    assert_eq(@dirs.dir("cache"), @dirs.cache_dir())
    assert_eq(@dirs.dir("config"), @dirs.config_dir())
    }

    #Supported names

    dir(kind) supports:

    • home
    • cache
    • config
    • executable
    • data
    • data_local
    • audio
    • desktop
    • document
    • download
    • font
    • picture
    • public
    • template
    • tmp
    • video

    Unsupported names return None.

    Each public function includes detailed documentation for platform-specific behavior.

    audio_dir

    fn audio_dir() -> String?

    Returns the current user's music directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_MUSIC_DIR, then HOME/Music
    macOSHOME/Music
    WindowsUSERPROFILE/Music, then HOMEDRIVE + HOMEPATH + Music

    cache_dir

    fn cache_dir() -> String?

    Returns the current user's cache directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_CACHE_HOME, then HOME/.cache
    macOSHOME/Library/Caches
    WindowsLOCALAPPDATA

    The function returns None when no applicable location can be constructed.

    config_dir

    fn config_dir() -> String?

    Returns the current user's configuration directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_CONFIG_HOME, then HOME/.config
    macOSHOME/Library/Preferences
    WindowsAPPDATA

    The function returns None when the required environment variables are not available.

    data_dir

    fn data_dir() -> String?

    Returns the current user's shared application data directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_DATA_HOME, then HOME/.local/share
    macOSHOME/Library/Application Support
    WindowsAPPDATA

    Use this location for data that should roam with the user profile when the platform supports it.

    data_local_dir

    fn data_local_dir() -> String?

    Returns the current user's machine-local application data directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxSame as data_dir()
    macOSSame as data_dir()
    WindowsLOCALAPPDATA

    This is the recommended location for data that should stay on the current machine instead of roaming with the profile.

    desktop_dir

    fn desktop_dir() -> String?

    Returns the current user's desktop directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_DESKTOP_DIR, then HOME/Desktop
    macOSHOME/Desktop
    WindowsUSERPROFILE/Desktop, then HOMEDRIVE + HOMEPATH + Desktop

    dir

    fn dir(kind : String) -> String?

    Returns a user-specific directory path for one of the supported directory names.

    This function is the MoonBit equivalent of dir("name") from justjavac/deno_dirs. It accepts the following names:

    NameMeaning
    "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

    When the required variables are missing, or when the current compilation target does not define the requested directory, the function returns None.

    Example

    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") is None)
    }

    document_dir

    fn document_dir() -> String?

    Returns the current user's documents directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_DOCUMENTS_DIR, then HOME/Documents
    macOSHOME/Documents
    WindowsUSERPROFILE/Documents, then HOMEDRIVE + HOMEPATH + Documents

    download_dir

    fn download_dir() -> String?

    Returns the current user's downloads directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_DOWNLOAD_DIR, then HOME/Downloads
    macOSHOME/Downloads
    WindowsUSERPROFILE/Downloads, then HOMEDRIVE + HOMEPATH + Downloads

    The function returns None when no home directory can be derived.

    executable_dir

    fn executable_dir() -> String?

    Returns the current user's executable directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_BIN_HOME, then XDG_DATA_HOME/../bin, then HOME/.local/bin
    macOSNot defined
    WindowsNot defined

    The function returns None on platforms where no standard user executable directory is defined.

    font_dir

    fn font_dir() -> String?

    Returns the current user's font directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_DATA_HOME/fonts, then HOME/.local/share/fonts
    macOSHOME/Library/Fonts
    WindowsNot defined

    home_dir

    fn home_dir() -> String?

    Returns the current user's home directory.

    Resolution follows the same platform rules as deno_dirs:

    PlatformResolution order
    LinuxHOME
    macOSHOME
    WindowsUSERPROFILE, then HOMEDRIVE + HOMEPATH

    If none of the relevant environment variables are available, this function returns None.

    picture_dir

    fn picture_dir() -> String?

    Returns the current user's pictures directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_PICTURES_DIR, then HOME/Pictures
    macOSHOME/Pictures
    WindowsUSERPROFILE/Pictures, then HOMEDRIVE + HOMEPATH + Pictures

    public_dir

    fn public_dir() -> String?

    Returns the public shared directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_PUBLICSHARE_DIR, then HOME/Public
    macOSHOME/Public
    WindowsPUBLIC, then SYSTEMDRIVE\\Users\\Public

    template_dir

    fn template_dir() -> String?

    Returns the current user's templates directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_TEMPLATES_DIR, then HOME/Templates
    macOSNot defined
    WindowsAPPDATA/Microsoft/Windows/Templates

    tmp_dir

    fn tmp_dir() -> String?

    Returns the preferred temporary directory for the current user session.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_RUNTIME_DIR/tmp, then TMPDIR, TEMP, TMP, then /var/tmp
    macOSTMPDIR
    WindowsTMP, then TEMP

    This function returns None only when the current compilation target does not define a temporary-directory location, or when the active platform exposes no usable temporary-directory environment variable.

    video_dir

    fn video_dir() -> String?

    Returns the current user's videos directory.

    Platform-specific resolution:

    PlatformResolution order
    LinuxXDG_VIDEOS_DIR, then HOME/Videos
    macOSHOME/Movies
    WindowsUSERPROFILE/Videos, then HOMEDRIVE + HOMEPATH + Videos

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io