Skip to content

path

The path module provides utilities for working with file and directory paths.

It is recommended to allowlist only the APIs you use for optimal bundle size and security.

AppCache: 16;

appCacheDir for more information.

AppConfig: 13;

appConfigDir for more information.

AppData: 14;

appDataDir for more information.

AppLocalData: 15;

appLocalDataDir for more information.

AppLog: 17;

appLogDir for more information.

Audio: 1;

audioDir for more information.

Cache: 2;

cacheDir for more information.

Config: 3;

configDir for more information.

Data: 4;

dataDir for more information.

Desktop: 18;

desktopDir for more information.

Document: 6;

documentDir for more information.

Download: 7;

downloadDir for more information.

Executable: 19;

executableDir for more information.

Font: 20;

fontDir for more information.

Home: 21;

homeDir for more information.

LocalData: 5;

localDataDir for more information.

Picture: 8;

pictureDir for more information.

Public: 9;

publicDir for more information.

Resource: 11;

resourceDir for more information.

Runtime: 22;

runtimeDir for more information.

Temp: 12;

tempDir for more information.

Template: 23;

templateDir for more information.

Video: 10;

videoDir for more information.

function appCacheDir(): Promise<string>

Returns the path to the suggested directory for your app’s cache files. Resolves to ${cacheDir}/${bundleIdentifier}, where bundleIdentifier is the identifier value configured in tauri.conf.json.

Promise<string>

import { appCacheDir } from '@crabnebula/taurify-api/path';
const appCacheDirPath = await appCacheDir();

function appConfigDir(): Promise<string>

Returns the path to the suggested directory for your app’s config files. Resolves to ${configDir}/${bundleIdentifier}, where bundleIdentifier is the identifier value configured in tauri.conf.json.

Promise<string>

import { appConfigDir } from '@crabnebula/taurify-api/path';
const appConfigDirPath = await appConfigDir();

function appDataDir(): Promise<string>

Returns the path to the suggested directory for your app’s data files. Resolves to ${dataDir}/${bundleIdentifier}, where bundleIdentifier is the identifier value configured in tauri.conf.json.

Promise<string>

import { appDataDir } from '@crabnebula/taurify-api/path';
const appDataDirPath = await appDataDir();

function appLocalDataDir(): Promise<string>

Returns the path to the suggested directory for your app’s local data files. Resolves to ${localDataDir}/${bundleIdentifier}, where bundleIdentifier is the identifier value configured in tauri.conf.json.

Promise<string>

import { appLocalDataDir } from '@crabnebula/taurify-api/path';
const appLocalDataDirPath = await appLocalDataDir();

function appLogDir(): Promise<string>

Returns the path to the suggested directory for your app’s log files.

  • Linux: Resolves to ${configDir}/${bundleIdentifier}/logs.
  • macOS: Resolves to ${homeDir}/Library/Logs/{bundleIdentifier}
  • Windows: Resolves to ${configDir}/${bundleIdentifier}/logs.

Promise<string>

import { appLogDir } from '@crabnebula/taurify-api/path';
const appLogDirPath = await appLogDir();

function audioDir(): Promise<string>

Returns the path to the user’s audio directory.

  • Linux: Resolves to xdg-user-dirsXDG_MUSIC_DIR.
  • macOS: Resolves to $HOME/Music.
  • Windows: Resolves to {FOLDERID_Music}.

Promise<string>

import { audioDir } from '@crabnebula/taurify-api/path';
const audioDirPath = await audioDir();

function basename(path, ext?): Promise<string>

Returns the last portion of a path. Trailing directory separators are ignored.

ParameterTypeDescription
pathstring-
ext?stringAn optional file extension to be removed from the returned path.

Promise<string>

import { basename } from '@crabnebula/taurify-api/path';
const base = await basename('path/to/app.conf');
assert(base === 'app.conf');

function cacheDir(): Promise<string>

Returns the path to the user’s cache directory.

  • Linux: Resolves to $XDG_CACHE_HOME or $HOME/.cache.
  • macOS: Resolves to $HOME/Library/Caches.
  • Windows: Resolves to {FOLDERID_LocalAppData}.

Promise<string>

import { cacheDir } from '@crabnebula/taurify-api/path';
const cacheDirPath = await cacheDir();

function configDir(): Promise<string>

Returns the path to the user’s config directory.

  • Linux: Resolves to $XDG_CONFIG_HOME or $HOME/.config.
  • macOS: Resolves to $HOME/Library/Application Support.
  • Windows: Resolves to {FOLDERID_RoamingAppData}.

Promise<string>

import { configDir } from '@crabnebula/taurify-api/path';
const configDirPath = await configDir();

function dataDir(): Promise<string>

Returns the path to the user’s data directory.

  • Linux: Resolves to $XDG_DATA_HOME or $HOME/.local/share.
  • macOS: Resolves to $HOME/Library/Application Support.
  • Windows: Resolves to {FOLDERID_RoamingAppData}.

Promise<string>

import { dataDir } from '@crabnebula/taurify-api/path';
const dataDirPath = await dataDir();

function delimiter(): string

Returns the platform-specific path segment delimiter:

  • ; on Windows
  • : on POSIX

string


function desktopDir(): Promise<string>

Returns the path to the user’s desktop directory.

  • Linux: Resolves to xdg-user-dirsXDG_DESKTOP_DIR.
  • macOS: Resolves to $HOME/Desktop.
  • Windows: Resolves to {FOLDERID_Desktop}.

Promise<string>

import { desktopDir } from '@crabnebula/taurify-api/path';
const desktopPath = await desktopDir();

function dirname(path): Promise<string>

Returns the parent directory of a given path. Trailing directory separators are ignored.

ParameterType
pathstring

Promise<string>

import { dirname } from '@crabnebula/taurify-api/path';
const dir = await dirname('/path/to/somedir/');
assert(dir === '/path/to');

function documentDir(): Promise<string>

Returns the path to the user’s document directory.

Promise<string>

import { documentDir } from '@crabnebula/taurify-api/path';
const documentDirPath = await documentDir();
  • Linux: Resolves to xdg-user-dirsXDG_DOCUMENTS_DIR.
  • macOS: Resolves to $HOME/Documents.
  • Windows: Resolves to {FOLDERID_Documents}.

function downloadDir(): Promise<string>

Returns the path to the user’s download directory.

  • Linux: Resolves to xdg-user-dirsXDG_DOWNLOAD_DIR.
  • macOS: Resolves to $HOME/Downloads.
  • Windows: Resolves to {FOLDERID_Downloads}.

Promise<string>

import { downloadDir } from '@crabnebula/taurify-api/path';
const downloadDirPath = await downloadDir();

function executableDir(): Promise<string>

Returns the path to the user’s executable directory.

  • Linux: Resolves to $XDG_BIN_HOME/../bin or $XDG_DATA_HOME/../bin or $HOME/.local/bin.
  • macOS: Not supported.
  • Windows: Not supported.

Promise<string>

import { executableDir } from '@crabnebula/taurify-api/path';
const executableDirPath = await executableDir();

function extname(path): Promise<string>

Returns the extension of the path.

ParameterType
pathstring

Promise<string>

import { extname } from '@crabnebula/taurify-api/path';
const ext = await extname('/path/to/file.html');
assert(ext === 'html');

function fontDir(): Promise<string>

Returns the path to the user’s font directory.

  • Linux: Resolves to $XDG_DATA_HOME/fonts or $HOME/.local/share/fonts.
  • macOS: Resolves to $HOME/Library/Fonts.
  • Windows: Not supported.

Promise<string>

import { fontDir } from '@crabnebula/taurify-api/path';
const fontDirPath = await fontDir();

function homeDir(): Promise<string>

Returns the path to the user’s home directory.

  • Linux: Resolves to $HOME.
  • macOS: Resolves to $HOME.
  • Windows: Resolves to {FOLDERID_Profile}.

Promise<string>

import { homeDir } from '@crabnebula/taurify-api/path';
const homeDirPath = await homeDir();

function isAbsolute(path): Promise<boolean>

Returns whether the path is absolute or not.

ParameterType
pathstring

Promise<boolean>

import { isAbsolute } from '@crabnebula/taurify-api/path';
assert(await isAbsolute('/home/tauri'));

function join(...paths): Promise<string>

Joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.

ParameterType
pathsstring[]

Promise<string>

import { join, appDataDir } from '@crabnebula/taurify-api/path';
const appDataDirPath = await appDataDir();
const path = await join(appDataDirPath, 'users', 'tauri', 'avatar.png');

function localDataDir(): Promise<string>

Returns the path to the user’s local data directory.

  • Linux: Resolves to $XDG_DATA_HOME or $HOME/.local/share.
  • macOS: Resolves to $HOME/Library/Application Support.
  • Windows: Resolves to {FOLDERID_LocalAppData}.

Promise<string>

import { localDataDir } from '@crabnebula/taurify-api/path';
const localDataDirPath = await localDataDir();

function normalize(path): Promise<string>

Normalizes the given path, resolving '..' and '.' segments and resolve symbolic links.

ParameterType
pathstring

Promise<string>

import { normalize, appDataDir } from '@crabnebula/taurify-api/path';
const appDataDirPath = await appDataDir();
const path = await normalize(`${appDataDirPath}/../users/tauri/avatar.png`);

function pictureDir(): Promise<string>

Returns the path to the user’s picture directory.

  • Linux: Resolves to xdg-user-dirsXDG_PICTURES_DIR.
  • macOS: Resolves to $HOME/Pictures.
  • Windows: Resolves to {FOLDERID_Pictures}.

Promise<string>

import { pictureDir } from '@crabnebula/taurify-api/path';
const pictureDirPath = await pictureDir();

function publicDir(): Promise<string>

Returns the path to the user’s public directory.

  • Linux: Resolves to xdg-user-dirsXDG_PUBLICSHARE_DIR.
  • macOS: Resolves to $HOME/Public.
  • Windows: Resolves to {FOLDERID_Public}.

Promise<string>

import { publicDir } from '@crabnebula/taurify-api/path';
const publicDirPath = await publicDir();

function resolve(...paths): Promise<string>

Resolves a sequence of paths or path segments into an absolute path.

ParameterType
pathsstring[]

Promise<string>

import { resolve, appDataDir } from '@crabnebula/taurify-api/path';
const appDataDirPath = await appDataDir();
const path = await resolve(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');

function resolveResource(resourcePath): Promise<string>

Resolve the path to a resource file.

ParameterTypeDescription
resourcePathstringThe path to the resource. Must follow the same syntax as defined in tauri.conf.json > bundle > resources, i.e. keeping subfolders and parent dir components (../).

Promise<string>

The full path to the resource.

import { resolveResource } from '@crabnebula/taurify-api/path';
const resourcePath = await resolveResource('script.sh');

function resourceDir(): Promise<string>

Returns the path to the application’s resource directory. To resolve a resource path, see resolveResource.

Although we provide the exact path where this function resolves to, this is not a contract and things might change in the future

  • Windows: Resolves to the directory that contains the main executable.
  • Linux: When running in an AppImage, the APPDIR variable will be set to the mounted location of the app, and the resource dir will be ${APPDIR}/usr/lib/${exe_name}. If not running in an AppImage, the path is /usr/lib/${exe_name}. When running the app from src-tauri/target/(debug|release)/, the path is ${exe_dir}/../lib/${exe_name}.
  • macOS: Resolves to ${exe_dir}/../Resources (inside .app).
  • iOS: Resolves to ${exe_dir}/assets.
  • Android: Currently the resources are stored in the APK as assets so it’s not a normal file system path, we return a special URI prefix asset://localhost/ here that can be used with the file system plugin,

Promise<string>

import { resourceDir } from '@crabnebula/taurify-api/path';
const resourceDirPath = await resourceDir();

function runtimeDir(): Promise<string>

Returns the path to the user’s runtime directory.

  • Linux: Resolves to $XDG_RUNTIME_DIR.
  • macOS: Not supported.
  • Windows: Not supported.

Promise<string>

import { runtimeDir } from '@crabnebula/taurify-api/path';
const runtimeDirPath = await runtimeDir();

function sep(): string

Returns the platform-specific path segment separator:

  • \ on Windows
  • / on POSIX

string


function tempDir(): Promise<string>

Returns a temporary directory.

Promise<string>

import { tempDir } from '@crabnebula/taurify-api/path';
const temp = await tempDir();

function templateDir(): Promise<string>

Returns the path to the user’s template directory.

  • Linux: Resolves to xdg-user-dirsXDG_TEMPLATES_DIR.
  • macOS: Not supported.
  • Windows: Resolves to {FOLDERID_Templates}.

Promise<string>

import { templateDir } from '@crabnebula/taurify-api/path';
const templateDirPath = await templateDir();

function videoDir(): Promise<string>

Returns the path to the user’s video directory.

  • Linux: Resolves to xdg-user-dirsXDG_VIDEOS_DIR.
  • macOS: Resolves to $HOME/Movies.
  • Windows: Resolves to {FOLDERID_Videos}.

Promise<string>

import { videoDir } from '@crabnebula/taurify-api/path';
const videoDirPath = await videoDir();