path
The path module provides utilities for working with file and directory paths.
This package is also accessible with window.__TAURI__.path
when app.withGlobalTauri
in tauri.conf.json
is set to true
.
It is recommended to allowlist only the APIs you use for optimal bundle size and security.
Enumerations
BaseDirectory
Since
2.0.0
Enumeration Members
AppCache
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L35
AppConfig
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L32
AppData
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L33
AppLocalData
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L34
AppLog
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L36
Audio
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L20
Cache
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L21
Config
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L22
Data
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L23
Desktop
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L37
Document
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L25
Download
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L26
Executable
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L38
Font
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L39
Home
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L40
LocalData
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L24
Picture
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L27
Public
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L28
Resource
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L30
Runtime
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L41
Temp
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L31
Template
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L42
Video
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L29
Functions
appCacheDir()
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
.
Returns
Promise
<string
>
Example
Since
1.2.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L107
appConfigDir()
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
.
Returns
Promise
<string
>
Example
Since
1.2.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L56
appDataDir()
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
.
Returns
Promise
<string
>
Example
Since
1.2.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L73
appLocalDataDir()
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
.
Returns
Promise
<string
>
Example
Since
1.2.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L90
appLogDir()
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
.
Returns
Promise
<string
>
Example
Since
1.2.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L519
audioDir()
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}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L129
basename()
Returns the last portion of a path
. Trailing directory separators are ignored.
Parameters
Parameter | Type | Description |
---|---|---|
path | string | - |
ext ? | string | An optional file extension to be removed from the returned path. |
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L649
cacheDir()
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}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L151
configDir()
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}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L173
dataDir()
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}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L195
delimiter()
Returns the platform-specific path segment delimiter:
;
on Windows:
on POSIX
Returns
string
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L559
desktopDir()
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}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L217
dirname()
Returns the directory name of a path
. Trailing directory separators are ignored.
Parameters
Parameter | Type |
---|---|
path | string |
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L618
documentDir()
Returns the path to the user’s document directory.
Returns
Promise
<string
>
Example
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
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L239
downloadDir()
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}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L261
executableDir()
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.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L283
extname()
Returns the extension of the path
.
Parameters
Parameter | Type |
---|---|
path | string |
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L633
fontDir()
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.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L305
homeDir()
Returns the path to the user’s home directory.
Platform-specific
- Linux: Resolves to
$HOME
. - macOS: Resolves to
$HOME
. - Windows: Resolves to
{FOLDERID_Profile}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L327
isAbsolute()
Returns whether the path is absolute or not.
Parameters
Parameter | Type |
---|---|
path | string |
Returns
Promise
<boolean
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L663
join()
Joins all given path
segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.
Parameters
Parameter | Type |
---|---|
…paths | string [] |
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L603
localDataDir()
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}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L349
normalize()
Normalizes the given path
, resolving '..'
and '.'
segments and resolve symbolic links.
Parameters
Parameter | Type |
---|---|
path | string |
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L588
pictureDir()
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}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L371
publicDir()
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}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L393
resolve()
Resolves a sequence of paths
or path
segments into an absolute path.
Parameters
Parameter | Type |
---|---|
…paths | string [] |
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L573
resolveResource()
Resolve the path to a resource file.
Parameters
Parameter | Type | Description |
---|---|---|
resourcePath | string | The 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 (../ ). |
Returns
Promise
<string
>
The full path to the resource.
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L430
resourceDir()
Returns the path to the application’s resource directory.
To resolve a resource path, see the [[resolveResource | resolveResource API
]].
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L410
runtimeDir()
Returns the path to the user’s runtime directory.
Platform-specific
- Linux: Resolves to
$XDG_RUNTIME_DIR
. - macOS: Not supported.
- Windows: Not supported.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L453
sep()
Returns the platform-specific path segment separator:
\
on Windows/
on POSIX
Returns
string
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L548
tempDir()
Returns a temporary directory.
Returns
Promise
<string
>
Example
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L535
templateDir()
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}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L475
videoDir()
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}
.
Returns
Promise
<string
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L497
© 2024 Tauri Contributors. CC-BY / MIT