Home

Awesome

Maven Central API documentation actively developed GitHub Actions status License: MPL-2.0

Directories

Introduction

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

Platforms

This library is written in Java, and runs on the JVM (≥ 6).

A version of this library implemented in Rust is provided by directories-rs.

Usage

Dependency

Add the library as a dependency to your project:

Maven
<dependency>
  <groupId>dev.dirs</groupId>
  <artifactId>directories</artifactId>
  <version>26</version>
</dependency>
Gradle
compile 'dev.dirs:directories:26'
SBT
"dev.dirs" % "directories" % "26"

The library itself is built against Java 6 to allow for the widest possible usage scenarios. It can be used on any Java version >= 6.

Example

Library run by user Alice:

import dev.dirs.ProjectDirectories;
import dev.dirs.BaseDirectories;
import dev.dirs.UserDirectories;

ProjectDirectories myProjDirs = ProjectDirectories.from("com", "Foo Corp", "Bar App");
myProjDirs.configDir;
// Lin: /home/alice/.config/barapp
// Mac: /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App
// Win: C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config

BaseDirectories baseDirs = BaseDirectories.get();
baseDirs.executableDir;
// Lin: /home/alice/.local/bin
// Mac: null
// Win: null

UserDirectories userDirs = UserDirectories.get();
userDirs.audioDir;
// Lin: /home/alice/Music
// Mac: /Users/Alice/Music
// Win: C:\Users\Alice\Music

Design Goals

Features

BaseDirectories

The intended use-case for BaseDirectories is to query the paths of user-invisible standard directories that have been defined according to the conventions of the operating system the library is running on.

If you want to compute the location of cache, config or data folders for your own application or project, use ProjectDirectories instead.

Field nameValue on Linux / BSD / SolarisValue on WindowsValue on macOS
homeDir$HOME{FOLDERID_UserProfile}$HOME
cacheDir$XDG_CACHE_HOME or $HOME/.cache{FOLDERID_LocalApplicationData}$HOME/Library/Caches
configDir$XDG_CONFIG_HOME or $HOME/.config{FOLDERID_ApplicationData}$HOME/Library/Application Support
dataDir$XDG_DATA_HOME or $HOME/.local/share{FOLDERID_ApplicationData}$HOME/Library/Application Support
dataLocalDir$XDG_DATA_HOME or $HOME/.local/share{FOLDERID_LocalApplicationData}$HOME/Library/Application Support
executableDir$XDG_BIN_HOME or $XDG_DATA_HOME/../bin or $HOME/.local/binnullnull
preferenceDir$XDG_CONFIG_HOME or $HOME/.config{FOLDERID_ApplicationData}$HOME/Library/Preferences
runtimeDir$XDG_RUNTIME_DIR or nullnullnull

UserDirectories

The intended use-case for UserDirectories is to query the paths of user-facing standard directories that have been defined according to the conventions of the operating system the library is running on.

Field nameValue on Linux / BSDValue on WindowsValue on macOS
homeDir$HOME{FOLDERID_UserProfile}$HOME
audioDirXDG_MUSIC_DIR{FOLDERID_Music}$HOME/Music
desktopDirXDG_DESKTOP_DIR{FOLDERID_Desktop}$HOME/Desktop
documentDirXDG_DOCUMENTS_DIR{FOLDERID_Documents}$HOME/Documents
downloadDirXDG_DOWNLOAD_DIR{FOLDERID_Downloads}$HOME/Downloads
fontDir$XDG_DATA_HOME/fonts or $HOME/.local/share/fontsnull$HOME/Library/Fonts
pictureDirXDG_PICTURES_DIR{FOLDERID_Pictures}$HOME/Pictures
publicDirXDG_PUBLICSHARE_DIR{FOLDERID_Public}$HOME/Public
templateDirXDG_TEMPLATES_DIR{FOLDERID_Templates}null
videoDirXDG_VIDEOS_DIR{FOLDERID_Videos}$HOME/Movies

ProjectDirectories

The intended use-case for ProjectDirectories is to compute the location of cache, config or data folders for your own application or project, which are derived from the standard directories.

Field nameValue on Linux / BSDValue on WindowsValue on macOS
cacheDir$XDG_CACHE_HOME/<project_path> or $HOME/.cache/<project_path>{FOLDERID_LocalApplicationData}/<project_path>/cache$HOME/Library/Caches/<project_path>
configDir$XDG_CONFIG_HOME/<project_path> or $HOME/.config/<project_path>{FOLDERID_ApplicationData}/<project_path>/config$HOME/Library/Application Support/<project_path>
dataDir$XDG_DATA_HOME/<project_path> or $HOME/.local/share/<project_path>{FOLDERID_ApplicationData}/<project_path>/data$HOME/Library/Application Support/<project_path>
dataLocalDir$XDG_DATA_HOME/<project_path> or $HOME/.local/share/<project_path>{FOLDERID_LocalApplicationData}/<project_path>/data$HOME/Library/Application Support/<project_path>
preferenceDir$XDG_CONFIG_HOME/<project_path> or $HOME/.config/<project_path>{FOLDERID_ApplicationData}/<project_path>/config$HOME/Library/Preferences/<project_path>
runtimeDir$XDG_RUNTIME_DIR/<project_path>nullnull

The specific value of <project_path> is computed by the

ProjectDirectories.from(String qualifier,
                        String organization,
                        String application)

method and varies across operating systems. As an example, calling

ProjectDirectories.from("org"         /*qualifier*/,
                        "Baz Corp"    /*organization*/,
                        "Foo Bar-App" /*application*/)

results in the following values:

Value on LinuxValue on WindowsValue on macOS
"foobar-app""Baz Corp/Foo Bar-App""org.Baz-Corp.Foo-Bar-App"

The ProjectDirectories.fromPath method allows the creation of ProjectDirectories instances directly from a project path. This argument is used verbatim and is not adapted to operating system standards. The use of ProjectDirectories.fromPath is strongly discouraged, as its results will not follow operating system standards on at least two of three platforms.

Versioning

The version number of this library consists of a whole number, which is incremented with each release.

Changelog

26 – current stable dev.dirs:directories release

25

24

23

22

21

20

19-13 – Reserved for bug fixes on soc.github.io

12 – current stable legacy soc.github.io release

Please refer to the legacy branch for the documentation and artifact coordinates of the soc.github.io artifact.

11

10

9

8

7

MethodOld valueNew Value
BaseDirectories.cacheDir{SpecialFolder.LocalApplicationData}/cache{SpecialFolder.LocalApplicationData}
ProjectDirectories#dataDir{SpecialFolder.ApplicationData}/<project_path>{SpecialFolder.ApplicationData}/<project_path>/data
ProjectDirectories#dataLocalDir{SpecialFolder.LocalApplicationData}/<project_path>{SpecialFolder.LocalApplicationData}/<project_path>/data

6

Old nameNew name
dataDirdataLocalDir
dataRoamingDirdataDir
executablesDirexecutableDir
documentsDirdocumentDir
downloadsDirdownloadDir
fontsDirfontDir
musicDiraudioDir
picturesDirpictureDir
templatesDirtemplateDir
videosDirvideoDir

5-1 – Unpublished beta releases