dirs

Build Status][gh-actions-badge]][gh-actions]
[![LFE Versions][lfe-badge]][lfe]
[![Erlang Versions][erlang-badge]][versions]
[![Tags][github-tags-badge] [ Downloads

A low-level library that provides standard config/cache/data paths, following the respective conventions on Linux, macOS and Windows (port of the Rust dirs library to LFE/Erlang)

Project Logo

Introduction

The library provides the location of these directories by leveraging the mechanisms defined by

Platforms

This library is written in LFE but can be used transparently in Erlang or Elixir projects (that support rebar3) as if it was an Erlang library. It supports Linux and macOS; Windows support is pending.

Usage

Library run by user alice in Erlang:

1> dirs:home().
%% Lin: /home/alice
%% Win: C:\Users\Alice
%% Mac: /Users/Alice

2> dirs:audio().
%% Lin: /home/alice/Music
%% Win: C:\Users\Alice\Music
%% Mac: /Users/Alice/Music

3> dirs:config().
%% Lin: /home/alice/.config
%% Win: C:\Users\Alice\AppData\Roaming
%% Mac: /Users/Alice/Library/Application Support

4> dirs:executable().
%% Lin: /home/alice/.local/bin
%% Win: undefined
%% Mac: undefined

In LFE:

lfe> (dirs:home)
;; Lin: /home/alice
;; Win: C:\Users\Alice
;; Mac: /Users/Alice

lfe> (dirs:audio)
;; Lin: /home/alice/Music
;; Win: C:\Users\Alice\Music
;; Mac: /Users/Alice/Music

lfe> (dirs:config)
;; Lin: /home/alice/.config
;; Win: C:\Users\Alice\AppData\Roaming
;; Mac: /Users/Alice/Library/Application Support

lfe> (dirs:executable)
;; Lin: /home/alice/.local/bin
;; Win: undefined
;; Mac: undefined

Note that all dirs:* functions support an additional arity, allowing one to append one or more path segments to the given directory:

1> dirs:home("lab").
"/Users/oubiwann/lab"
2> dirs:home(["lab", "lfe"]).
"/Users/oubiwann/lab/lfe"
3> dirs:video(["Conferences", "EUC", 2019, drafts]).
"/Users/oubiwann/Movies/Conferences/EUC/2019/drafts"
4> dirs:cache([2023,11,27,d34db33fcafe,0,1,5,12,42]).
"/Users/oubiwann/Library/Caches/2023/11/27/d34db33fcafe/0/1/5/12/42"

Design Goals

Features

Function name Value on Linux/Redox Value on Windows (not yet impl) Value on macOS
dirs:home$HOME{FOLDERID_Profile}$HOME
dirs:cache$XDG_CACHE_HOME or $HOME/.cache{FOLDERID_LocalAppData}$HOME/Library/Caches
dirs:config$XDG_CONFIG_HOME or $HOME/.config{FOLDERID_RoamingAppData}$HOME/Library/Application Support
dirs:config_local and dirs:config-local$XDG_CONFIG_HOME or $HOME/.config{FOLDERID_LocalAppData}$HOME/Library/Application Support
dirs:data$XDG_DATA_HOME or $HOME/.local/share{FOLDERID_RoamingAppData}$HOME/Library/Application Support
dirs:data_local and dirs::data-local$XDG_DATA_HOME or $HOME/.local/share{FOLDERID_LocalAppData}$HOME/Library/Application Support
dirs:executable$XDG_BIN_HOME or $HOME/.local/binundefinedundefined
dirs:preference$XDG_CONFIG_HOME or $HOME/.config{FOLDERID_RoamingAppData}$HOME/Library/Preferences
dirs:runtime$XDG_RUNTIME_DIR or undefinedundefinedundefined
dirs:state$XDG_STATE_HOME or $HOME/.local/stateundefinedundefined
dirs:audioXDG_MUSIC_DIR or undefined{FOLDERID_Music}$HOME/Music
dirs:desktopXDG_DESKTOP_DIR or undefined{FOLDERID_Desktop}$HOME/Desktop
dirs:documentXDG_DOCUMENTS_DIR or undefined{FOLDERID_Documents}$HOME/Documents
dirs:downloadXDG_DOWNLOAD_DIR or undefined{FOLDERID_Downloads}$HOME/Downloads
dirs:font$XDG_DATA_HOME/fonts or $HOME/.local/share/fontsundefined$HOME/Library/Fonts
dirs:pictureXDG_PICTURES_DIR or undefined{FOLDERID_Pictures}$HOME/Pictures
dirs:publicXDG_PUBLICSHARE_DIR or undefined{FOLDERID_Public}$HOME/Public
dirs:templateXDG_TEMPLATES_DIR or undefined{FOLDERID_Templates}undefined
dirs:videoXDG_VIDEOS_DIR or undefined{FOLDERID_Videos}$HOME/Movies

License

Apache License, Version 2.0

Copyright © 2023-2025, Duncan McGreggor oubiwann@gmail.com.