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/tooling/api/src/path.ts#L35
AppConfig
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L32
AppData
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L33
AppLocalData
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L34
AppLog
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L36
Audio
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L20
Cache
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L21
Config
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L22
Data
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L23
Desktop
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L38
Document
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L25
Download
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L26
Executable
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L39
Font
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L40
Home
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L41
LocalData
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L24
Picture
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L27
Public
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L28
Resource
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L30
Runtime
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L42
Temp
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L31
Template
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L43
Video
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/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 value tauri.bundle.identifier
is configured in tauri.conf.json
.
Returns
Promise
<string
>
Example
Since
1.2.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L108
appConfigDir()
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
.
Returns
Promise
<string
>
Example
Since
1.2.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L57
appDataDir()
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
.
Returns
Promise
<string
>
Example
Since
1.2.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L74
appLocalDataDir()
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
.
Returns
Promise
<string
>
Example
Since
1.2.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L91
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/tooling/api/src/path.ts#L520
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/tooling/api/src/path.ts#L130
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/tooling/api/src/path.ts#L650
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/tooling/api/src/path.ts#L152
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/tooling/api/src/path.ts#L174
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/tooling/api/src/path.ts#L196
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/tooling/api/src/path.ts#L560
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/tooling/api/src/path.ts#L218
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/tooling/api/src/path.ts#L619
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/tooling/api/src/path.ts#L240
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/tooling/api/src/path.ts#L262
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/tooling/api/src/path.ts#L284
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/tooling/api/src/path.ts#L634
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/tooling/api/src/path.ts#L306
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/tooling/api/src/path.ts#L328
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/tooling/api/src/path.ts#L664
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/tooling/api/src/path.ts#L604
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/tooling/api/src/path.ts#L350
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/tooling/api/src/path.ts#L589
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/tooling/api/src/path.ts#L372
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/tooling/api/src/path.ts#L394
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/tooling/api/src/path.ts#L574
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/tooling/api/src/path.ts#L431
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/tooling/api/src/path.ts#L411
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/tooling/api/src/path.ts#L454
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/tooling/api/src/path.ts#L549
tempDir()
Returns a temporary directory.
Returns
Promise
<string
>
Example
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/path.ts#L536
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/tooling/api/src/path.ts#L476
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/tooling/api/src/path.ts#L498
© 2024 Tauri Contributors. CC-BY / MIT