Skip to content

Repository files navigation

Xdg.Directories

A .NET Standard library for the XDG Base Directory Specification and XDG user directories.

GitHub Actions Workflow Status NuGet Version Documentation MIT License

Xdg.Directories is a small (the .dll is only 11 KB), fast and portable (Completely supports .NET Standard 2.0) .NET implementation of the XDG Base Directory Specification and XDG user directories for Windows, MacOS and Linux/FreeBSD.

Full documentation can be found at https://xdg-net.github.io/Xdg.Directories.

Installation

Use NuGet to install Xdg.Directories.

From the .NET CLI:

dotnet add package Xdg.Directories

or from Visual Studio's package manager:

Install-Package Xdg.Directories

Pre-releases

Preview releases are uploaded to both GitHub packages (need GitHub account to download) and Forgejo packages (no login required).

Usage

Base Directories, C#

using System;
using System.IO;
using Xdg.Directories;

// Prints the current data directory
Console.Writeline(BaseDirectory.DataHome);

// Create and open a new cache file under the "foo" directory
FileStream file = File.Open(BaseDirectory.CacheFile("foo/bar.json"), FileMode.OpenOrCreate);

User Directories, F#

open System.IO
open Xdg.Directories

// Prints /home/$USER/Desktop
printfn "%s" UserDirectory.DesktopDir

// Get all of the entries in the Documents folder
let entries = Directory.GetFileSystemEntries(UserDirectory.DocumentsDir)

License

This project is licensed under the MIT license.
Icon is made by Emoji One, CC BY-SA 4.0, via Wikimedia Commons.