path
The path module provides utilities for working with file and directory paths.
This package is also accessible with window.__TAURI__.path
when build.withGlobalTauri
in tauri.conf.json
is set to true
.
The APIs must be added to tauri.allowlist.path
in tauri.conf.json
:
{
"tauri": {
"allowlist": {
"path": {
"all": true, // enable all Path APIs
}
}
}
}
It is recommended to allowlist only the APIs you use for optimal bundle size and security.
Referencesβ
BaseDirectory
β
Re-exports BaseDirectory
Variablesβ
delimiter
β
Const
delimiter:";"
|":"
Provides the platform-specific path segment delimiter:
;
on Windows:
on POSIX
Since: 1.0.0
Defined in: path.ts:660
sep
β
Const
sep:"\\"
|"/"
Provides the platform-specific path segment separator:
\
on Windows/
on POSIX
Since: 1.0.0
Defined in: path.ts:651
Functionsβ
appCacheDir
β
appCacheDir():
Promise
<string
>
Returns the path to the suggested directory for your app's cache files.
Resolves to ${cacheDir}/${bundleIdentifier}
, where bundleIdentifier
is the value tauri.bundle.identifier
is configured in tauri.conf.json
.
Example
import { appCacheDir } from '@tauri-apps/api/path';
const appCacheDirPath = await appCacheDir();
Since: 1.2.0
Returns: Promise
<string
>
appConfigDir
β
appConfigDir():
Promise
<string
>
Returns the path to the suggested directory for your app's config files.
Resolves to ${configDir}/${bundleIdentifier}
, where bundleIdentifier
is the value tauri.bundle.identifier
is configured in tauri.conf.json
.
Example
import { appConfigDir } from '@tauri-apps/api/path';
const appConfigDirPath = await appConfigDir();
Since: 1.2.0
Returns: Promise
<string
>
appDataDir
β
appDataDir():
Promise
<string
>
Returns the path to the suggested directory for your app's data files.
Resolves to ${dataDir}/${bundleIdentifier}
, where bundleIdentifier
is the value tauri.bundle.identifier
is configured in tauri.conf.json
.
Example
import { appDataDir } from '@tauri-apps/api/path';
const appDataDirPath = await appDataDir();
Since: 1.2.0
Returns: Promise
<string
>
appDir
β
appDir():
Promise
<string
>
Returns the path to the suggested directory for your app config files.
Deprecated
since 1.2.0: Will be removed in 2.0.0. Use appConfigDir or appDataDir instead.
Since: 1.0.0
Returns: Promise
<string
>
appLocalDataDir
β
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 value tauri.bundle.identifier
is configured in tauri.conf.json
.
Example
import { appLocalDataDir } from '@tauri-apps/api/path';
const appLocalDataDirPath = await appLocalDataDir();
Since: 1.2.0
Returns: Promise
<string
>
appLogDir
β
appLogDir():
Promise
<string
>
Returns the path to the suggested directory for your app's log files.
Platform-specificβ
- Linux: Resolves to
${configDir}/${bundleIdentifier}/logs
. - macOS: Resolves to
${homeDir}/Library/Logs/{bundleIdentifier}
- Windows: Resolves to
${configDir}/${bundleIdentifier}/logs
.
Example
import { appLogDir } from '@tauri-apps/api/path';
const appLogDirPath = await appLogDir();
Since: 1.2.0
Returns: Promise
<string
>
audioDir
β
audioDir():
Promise
<string
>
Returns the path to the user's audio directory.
Platform-specificβ
- Linux: Resolves to
xdg-user-dirs
'XDG_MUSIC_DIR
. - macOS: Resolves to
$HOME/Music
. - Windows: Resolves to
{FOLDERID_Music}
.
Example
import { audioDir } from '@tauri-apps/api/path';
const audioDirPath = await audioDir();
Since: 1.0.0
Returns: Promise
<string
>
basename
β
basename(
path
:string
,ext?
:string
):Promise
<string
>
Returns the last portion of a path
. Trailing directory separators are ignored.
Example
import { basename, resolveResource } from '@tauri-apps/api/path';
const resourcePath = await resolveResource('app.conf');
const base = await basename(resourcePath);
assert(base === 'app.conf');
Since: 1.0.0
Parameters
Name | Type | Description |
---|---|---|
path | string | - |
ext? | string | An optional file extension to be removed from the returned path. |
Returns: Promise
<string
>
cacheDir
β
cacheDir():
Promise
<string
>
Returns the path to the user's cache directory.
Platform-specificβ
- Linux: Resolves to
$XDG_CACHE_HOME
or$HOME/.cache
. - macOS: Resolves to
$HOME/Library/Caches
. - Windows: Resolves to
{FOLDERID_LocalAppData}
.
Example
import { cacheDir } from '@tauri-apps/api/path';
const cacheDirPath = await cacheDir();
Since: 1.0.0
Returns: Promise
<string
>
configDir
β
configDir():
Promise
<string
>
Returns the path to the user's config directory.
Platform-specificβ
- Linux: Resolves to
$XDG_CONFIG_HOME
or$HOME/.config
. - macOS: Resolves to
$HOME/Library/Application Support
. - Windows: Resolves to
{FOLDERID_RoamingAppData}
.
Example
import { configDir } from '@tauri-apps/api/path';
const configDirPath = await configDir();
Since: 1.0.0
Returns: Promise
<string
>
dataDir
β
dataDir():
Promise
<string
>
Returns the path to the user's data directory.
Platform-specificβ
- Linux: Resolves to
$XDG_DATA_HOME
or$HOME/.local/share
. - macOS: Resolves to
$HOME/Library/Application Support
. - Windows: Resolves to
{FOLDERID_RoamingAppData}
.
Example
import { dataDir } from '@tauri-apps/api/path';
const dataDirPath = await dataDir();
Since: 1.0.0
Returns: Promise
<string
>
desktopDir
β
desktopDir():
Promise
<string
>
Returns the path to the user's desktop directory.
Platform-specificβ
- Linux: Resolves to
xdg-user-dirs
'XDG_DESKTOP_DIR
. - macOS: Resolves to
$HOME/Desktop
. - Windows: Resolves to
{FOLDERID_Desktop}
.
Example
import { desktopDir } from '@tauri-apps/api/path';
const desktopPath = await desktopDir();
Since: 1.0.0
Returns: Promise
<string
>
dirname
β
dirname(
path
:string
):Promise
<string
>
Returns the directory name of a path
. Trailing directory separators are ignored.
Example
import { dirname, appDataDir } from '@tauri-apps/api/path';
const appDataDirPath = await appDataDir();
const dir = await dirname(appDataDirPath);
Since: 1.0.0
Parameters
Name | Type |
---|---|
path | string |
Returns: Promise
<string
>
documentDir
β
documentDir():
Promise
<string
>
Returns the path to the user's document directory.
Example
import { documentDir } from '@tauri-apps/api/path';
const documentDirPath = await documentDir();
Platform-specificβ
- Linux: Resolves to
xdg-user-dirs
'XDG_DOCUMENTS_DIR
. - macOS: Resolves to
$HOME/Documents
. - Windows: Resolves to
{FOLDERID_Documents}
.
Since: 1.0.0
Returns: Promise
<string
>
downloadDir
β
downloadDir():
Promise
<string
>
Returns the path to the user's download directory.
Platform-specificβ
- Linux: Resolves to
xdg-user-dirs
'XDG_DOWNLOAD_DIR
. - macOS: Resolves to
$HOME/Downloads
. - Windows: Resolves to
{FOLDERID_Downloads}
.
Example
import { downloadDir } from '@tauri-apps/api/path';
const downloadDirPath = await downloadDir();
Since: 1.0.0
Returns: Promise
<string
>
executableDir
β
executableDir():
Promise
<string
>
Returns the path to the user's executable directory.
Platform-specificβ
- Linux: Resolves to
$XDG_BIN_HOME/../bin
or$XDG_DATA_HOME/../bin
or$HOME/.local/bin
. - macOS: Not supported.
- Windows: Not supported.
Example
import { executableDir } from '@tauri-apps/api/path';
const executableDirPath = await executableDir();
Since: 1.0.0
Returns: Promise
<string
>
extname
β
extname(
path
:string
):Promise
<string
>
Returns the extension of the path
.
Example
import { extname, resolveResource } from '@tauri-apps/api/path';
const resourcePath = await resolveResource('app.conf');
const ext = await extname(resourcePath);
assert(ext === 'conf');
Since: 1.0.0
Parameters
Name | Type |
---|---|
path | string |
Returns: Promise
<string
>
fontDir
β
fontDir():
Promise
<string
>
Returns the path to the user's font directory.
Platform-specificβ
- Linux: Resolves to
$XDG_DATA_HOME/fonts
or$HOME/.local/share/fonts
. - macOS: Resolves to
$HOME/Library/Fonts
. - Windows: Not supported.
Example
import { fontDir } from '@tauri-apps/api/path';
const fontDirPath = await fontDir();
Since: 1.0.0
Returns: Promise
<string
>
homeDir
β
homeDir():
Promise
<string
>
Returns the path to the user's home directory.
Platform-specificβ
- Linux: Resolves to
$HOME
. - macOS: Resolves to
$HOME
. - Windows: Resolves to
{FOLDERID_Profile}
.
Example
import { homeDir } from '@tauri-apps/api/path';
const homeDirPath = await homeDir();
Since: 1.0.0
Returns: Promise
<string
>
isAbsolute
β
isAbsolute(
path
:string
):Promise
<boolean
>
Returns whether the path is absolute or not.
Example
import { isAbsolute } from '@tauri-apps/api/path';
assert(await isAbsolute('/home/tauri'));
Since: 1.0.0
Parameters
Name | Type |
---|---|
path | string |
Returns: Promise
<boolean
>
join
β
join(...
paths
:string
[]):Promise
<string
>
Joins all given path
segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.
Example
import { join, appDataDir } from '@tauri-apps/api/path';
const appDataDirPath = await appDataDir();
const path = await join(appDataDirPath, 'users', 'tauri', 'avatar.png');
Since: 1.0.0
Parameters
Name | Type |
---|---|
...paths | string [] |
Returns: Promise
<string
>
localDataDir
β
localDataDir():
Promise
<string
>
Returns the path to the user's local data directory.
Platform-specificβ
- Linux: Resolves to
$XDG_DATA_HOME
or$HOME/.local/share
. - macOS: Resolves to
$HOME/Library/Application Support
. - Windows: Resolves to
{FOLDERID_LocalAppData}
.
Example
import { localDataDir } from '@tauri-apps/api/path';
const localDataDirPath = await localDataDir();
Since: 1.0.0
Returns: Promise
<string
>
logDir
β
logDir():
Promise
<string
>
Returns the path to the suggested log directory.
Deprecated
since 1.2.0: Will be removed in 2.0.0. Use appLogDir instead.
Since: 1.0.0
Returns: Promise
<string
>
normalize
β
normalize(
path
:string
):Promise
<string
>
Normalizes the given path
, resolving '..'
and '.'
segments and resolve symbolic links.
Example
import { normalize, appDataDir } from '@tauri-apps/api/path';
const appDataDirPath = await appDataDir();
const path = await normalize(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');
Since: 1.0.0
Parameters
Name | Type |
---|---|
path | string |
Returns: Promise
<string
>
pictureDir
β
pictureDir():
Promise
<string
>
Returns the path to the user's picture directory.
Platform-specificβ
- Linux: Resolves to
xdg-user-dirs
'XDG_PICTURES_DIR
. - macOS: Resolves to
$HOME/Pictures
. - Windows: Resolves to
{FOLDERID_Pictures}
.
Example
import { pictureDir } from '@tauri-apps/api/path';
const pictureDirPath = await pictureDir();
Since: 1.0.0
Returns: Promise
<string
>
publicDir
β
publicDir():
Promise
<string
>
Returns the path to the user's public directory.
Platform-specificβ
- Linux: Resolves to
xdg-user-dirs
'XDG_PUBLICSHARE_DIR
. - macOS: Resolves to
$HOME/Public
. - Windows: Resolves to
{FOLDERID_Public}
.
Example
import { publicDir } from '@tauri-apps/api/path';
const publicDirPath = await publicDir();
Since: 1.0.0
Returns: Promise
<string
>
resolve
β
resolve(...
paths
:string
[]):Promise
<string
>
Resolves a sequence of paths
or path
segments into an absolute path.
Example
import { resolve, appDataDir } from '@tauri-apps/api/path';
const appDataDirPath = await appDataDir();
const path = await resolve(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');
Since: 1.0.0
Parameters
Name | Type |
---|---|
...paths | string [] |
Returns: Promise
<string
>
resolveResource
β
resolveResource(
resourcePath
:string
):Promise
<string
>
Resolve the path to a resource file.
Example
import { resolveResource } from '@tauri-apps/api/path';
const resourcePath = await resolveResource('script.sh');
Since: 1.0.0
Parameters
Name | Type | Description |
---|---|---|
resourcePath | string | The path to the resource. Must follow the same syntax as defined in tauri.conf.json > tauri > bundle > resources , i.e. keeping subfolders and parent dir components (../ ). |
Returns: Promise
<string
>
The full path to the resource.
resourceDir
β
resourceDir():
Promise
<string
>
Returns the path to the application's resource directory.
To resolve a resource path, see the [[resolveResource | resolveResource API
]].
Example
import { resourceDir } from '@tauri-apps/api/path';
const resourceDirPath = await resourceDir();
Since: 1.0.0
Returns: Promise
<string
>
runtimeDir
β
runtimeDir():
Promise
<string
>
Returns the path to the user's runtime directory.
Platform-specificβ
- Linux: Resolves to
$XDG_RUNTIME_DIR
. - macOS: Not supported.
- Windows: Not supported.
Example
import { runtimeDir } from '@tauri-apps/api/path';
const runtimeDirPath = await runtimeDir();
Since: 1.0.0
Returns: Promise
<string
>
templateDir
β
templateDir():
Promise
<string
>
Returns the path to the user's template directory.
Platform-specificβ
- Linux: Resolves to
xdg-user-dirs
'XDG_TEMPLATES_DIR
. - macOS: Not supported.
- Windows: Resolves to
{FOLDERID_Templates}
.
Example
import { templateDir } from '@tauri-apps/api/path';
const templateDirPath = await templateDir();
Since: 1.0.0
Returns: Promise
<string
>
videoDir
β
videoDir():
Promise
<string
>
Returns the path to the user's video directory.
Platform-specificβ
- Linux: Resolves to
xdg-user-dirs
'XDG_VIDEOS_DIR
. - macOS: Resolves to
$HOME/Movies
. - Windows: Resolves to
{FOLDERID_Videos}
.
Example
import { videoDir } from '@tauri-apps/api/path';
const videoDirPath = await videoDir();
Since: 1.0.0
Returns: Promise
<string
>