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
Section titled “Enumerations”BaseDirectory
Section titled “BaseDirectory”Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L19
2.0.0
Enumeration Members
Section titled “Enumeration Members”AppCache
Section titled “AppCache”AppCache: 16;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L83
appCacheDir for more information.
AppConfig
Section titled “AppConfig”AppConfig: 13;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L71
appConfigDir for more information.
AppData
Section titled “AppData”AppData: 14;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L75
appDataDir for more information.
AppLocalData
Section titled “AppLocalData”AppLocalData: 15;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L79
appLocalDataDir for more information.
AppLog
Section titled “AppLog”AppLog: 17;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L87
appLogDir for more information.
Audio: 1;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L23
audioDir for more information.
Cache: 2;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L27
cacheDir for more information.
Config
Section titled “Config”Config: 3;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L31
configDir for more information.
Data: 4;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L35
dataDir for more information.
Desktop
Section titled “Desktop”Desktop: 18;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L91
desktopDir for more information.
Document
Section titled “Document”Document: 6;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L43
documentDir for more information.
Download
Section titled “Download”Download: 7;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L47
downloadDir for more information.
Executable
Section titled “Executable”Executable: 19;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L95
executableDir for more information.
Font: 20;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L99
fontDir for more information.
Home: 21;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L103
homeDir for more information.
LocalData
Section titled “LocalData”LocalData: 5;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L39
localDataDir for more information.
Picture
Section titled “Picture”Picture: 8;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L51
pictureDir for more information.
Public
Section titled “Public”Public: 9;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L55
publicDir for more information.
Resource
Section titled “Resource”Resource: 11;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L63
resourceDir for more information.
Runtime
Section titled “Runtime”Runtime: 22;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L107
runtimeDir for more information.
Temp: 12;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L67
tempDir for more information.
Template
Section titled “Template”Template: 23;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L111
templateDir for more information.
Video: 10;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L59
videoDir for more information.
Functions
Section titled “Functions”appCacheDir()
Section titled “appCacheDir()”function appCacheDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L176
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { appCacheDir } from '@tauri-apps/api/path';const appCacheDirPath = await appCacheDir();1.2.0
appConfigDir()
Section titled “appConfigDir()”function appConfigDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L125
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { appConfigDir } from '@tauri-apps/api/path';const appConfigDirPath = await appConfigDir();1.2.0
appDataDir()
Section titled “appDataDir()”function appDataDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L142
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { appDataDir } from '@tauri-apps/api/path';const appDataDirPath = await appDataDir();1.2.0
appLocalDataDir()
Section titled “appLocalDataDir()”function appLocalDataDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L159
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { appLocalDataDir } from '@tauri-apps/api/path';const appLocalDataDirPath = await appLocalDataDir();1.2.0
appLogDir()
Section titled “appLogDir()”function appLogDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L604
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { appLogDir } from '@tauri-apps/api/path';const appLogDirPath = await appLogDir();1.2.0
audioDir()
Section titled “audioDir()”function audioDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L198
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { audioDir } from '@tauri-apps/api/path';const audioDirPath = await audioDir();1.0.0
basename()
Section titled “basename()”function basename(path, ext?): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L734
Returns the last portion of a path. Trailing directory separators are ignored.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
path |
string |
- |
ext? |
string |
An optional file extension to be removed from the returned path. |
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { basename } from '@tauri-apps/api/path';const base = await basename('path/to/app.conf');assert(base === 'app.conf');1.0.0
cacheDir()
Section titled “cacheDir()”function cacheDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L220
Returns the path to the user’s cache directory.
Platform-specific
- Linux: Resolves to
$XDG_CACHE_HOMEor$HOME/.cache. - macOS: Resolves to
$HOME/Library/Caches. - Windows: Resolves to
{FOLDERID_LocalAppData}.
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { cacheDir } from '@tauri-apps/api/path';const cacheDirPath = await cacheDir();1.0.0
configDir()
Section titled “configDir()”function configDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L242
Returns the path to the user’s config directory.
Platform-specific
- Linux: Resolves to
$XDG_CONFIG_HOMEor$HOME/.config. - macOS: Resolves to
$HOME/Library/Application Support. - Windows: Resolves to
{FOLDERID_RoamingAppData}.
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { configDir } from '@tauri-apps/api/path';const configDirPath = await configDir();1.0.0
dataDir()
Section titled “dataDir()”function dataDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L264
Returns the path to the user’s data directory.
Platform-specific
- Linux: Resolves to
$XDG_DATA_HOMEor$HOME/.local/share. - macOS: Resolves to
$HOME/Library/Application Support. - Windows: Resolves to
{FOLDERID_RoamingAppData}.
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { dataDir } from '@tauri-apps/api/path';const dataDirPath = await dataDir();1.0.0
delimiter()
Section titled “delimiter()”function delimiter(): string;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L644
Returns the platform-specific path segment delimiter:
;on Windows:on POSIX
Returns
Section titled “Returns”string
2.0.0
desktopDir()
Section titled “desktopDir()”function desktopDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L286
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { desktopDir } from '@tauri-apps/api/path';const desktopPath = await desktopDir();1.0.0
dirname()
Section titled “dirname()”function dirname(path): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L703
Returns the parent directory of a given path. Trailing directory separators are ignored.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string |
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { dirname } from '@tauri-apps/api/path';const dir = await dirname('/path/to/somedir/');assert(dir === '/path/to');1.0.0
documentDir()
Section titled “documentDir()”function documentDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L308
Returns the path to the user’s document directory.
Returns
Section titled “Returns”Promise<string>
Example
Section titled “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}.
1.0.0
downloadDir()
Section titled “downloadDir()”function downloadDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L330
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { downloadDir } from '@tauri-apps/api/path';const downloadDirPath = await downloadDir();1.0.0
executableDir()
Section titled “executableDir()”function executableDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L352
Returns the path to the user’s executable directory.
Platform-specific
- Linux: Resolves to
$XDG_BIN_HOME/../binor$XDG_DATA_HOME/../binor$HOME/.local/bin. - macOS: Not supported.
- Windows: Not supported.
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { executableDir } from '@tauri-apps/api/path';const executableDirPath = await executableDir();1.0.0
extname()
Section titled “extname()”function extname(path): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L718
Returns the extension of the path.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string |
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { extname } from '@tauri-apps/api/path';const ext = await extname('/path/to/file.html');assert(ext === 'html');1.0.0
fontDir()
Section titled “fontDir()”function fontDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L374
Returns the path to the user’s font directory.
Platform-specific
- Linux: Resolves to
$XDG_DATA_HOME/fontsor$HOME/.local/share/fonts. - macOS: Resolves to
$HOME/Library/Fonts. - Windows: Not supported.
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { fontDir } from '@tauri-apps/api/path';const fontDirPath = await fontDir();1.0.0
homeDir()
Section titled “homeDir()”function homeDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L396
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { homeDir } from '@tauri-apps/api/path';const homeDirPath = await homeDir();1.0.0
isAbsolute()
Section titled “isAbsolute()”function isAbsolute(path): Promise<boolean>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L748
Returns whether the path is absolute or not.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string |
Returns
Section titled “Returns”Promise<boolean>
Example
Section titled “Example”import { isAbsolute } from '@tauri-apps/api/path';assert(await isAbsolute('/home/tauri'));1.0.0
join()
Section titled “join()”function join(...paths): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L688
Joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…paths |
string[] |
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { join, appDataDir } from '@tauri-apps/api/path';const appDataDirPath = await appDataDir();const path = await join(appDataDirPath, 'users', 'tauri', 'avatar.png');1.0.0
localDataDir()
Section titled “localDataDir()”function localDataDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L418
Returns the path to the user’s local data directory.
Platform-specific
- Linux: Resolves to
$XDG_DATA_HOMEor$HOME/.local/share. - macOS: Resolves to
$HOME/Library/Application Support. - Windows: Resolves to
{FOLDERID_LocalAppData}.
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { localDataDir } from '@tauri-apps/api/path';const localDataDirPath = await localDataDir();1.0.0
normalize()
Section titled “normalize()”function normalize(path): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L673
Normalizes the given path, resolving '..' and '.' segments and resolve symbolic links.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string |
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { normalize, appDataDir } from '@tauri-apps/api/path';const appDataDirPath = await appDataDir();const path = await normalize(`${appDataDirPath}/../users/tauri/avatar.png`);1.0.0
pictureDir()
Section titled “pictureDir()”function pictureDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L440
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { pictureDir } from '@tauri-apps/api/path';const pictureDirPath = await pictureDir();1.0.0
publicDir()
Section titled “publicDir()”function publicDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L462
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { publicDir } from '@tauri-apps/api/path';const publicDirPath = await publicDir();1.0.0
resolve()
Section titled “resolve()”function resolve(...paths): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L658
Resolves a sequence of paths or path segments into an absolute path.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…paths |
string[] |
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { resolve, appDataDir } from '@tauri-apps/api/path';const appDataDirPath = await appDataDir();const path = await resolve(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');1.0.0
resolveResource()
Section titled “resolveResource()”function resolveResource(resourcePath): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L515
Resolve the path to a resource file.
Parameters
Section titled “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
Section titled “Returns”Promise<string>
The full path to the resource.
Example
Section titled “Example”import { resolveResource } from '@tauri-apps/api/path';const resourcePath = await resolveResource('script.sh');1.0.0
resourceDir()
Section titled “resourceDir()”function resourceDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L495
Returns the path to the application’s resource directory.
To resolve a resource path, see resolveResource.
Platform-specific
Section titled “Platform-specific”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
APPDIRvariable 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 fromsrc-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,
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { resourceDir } from '@tauri-apps/api/path';const resourceDirPath = await resourceDir();1.0.0
runtimeDir()
Section titled “runtimeDir()”function runtimeDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L538
Returns the path to the user’s runtime directory.
Platform-specific
- Linux: Resolves to
$XDG_RUNTIME_DIR. - macOS: Not supported.
- Windows: Not supported.
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { runtimeDir } from '@tauri-apps/api/path';const runtimeDirPath = await runtimeDir();1.0.0
function sep(): string;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L633
Returns the platform-specific path segment separator:
\on Windows/on POSIX
Returns
Section titled “Returns”string
2.0.0
tempDir()
Section titled “tempDir()”function tempDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L620
Returns a temporary directory.
Returns
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { tempDir } from '@tauri-apps/api/path';const temp = await tempDir();2.0.0
templateDir()
Section titled “templateDir()”function templateDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L560
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { templateDir } from '@tauri-apps/api/path';const templateDirPath = await templateDir();1.0.0
videoDir()
Section titled “videoDir()”function videoDir(): Promise<string>;Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/path.ts#L582
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
Section titled “Returns”Promise<string>
Example
Section titled “Example”import { videoDir } from '@tauri-apps/api/path';const videoDirPath = await videoDir();1.0.0
© 2026 Tauri Contributors. CC-BY / MIT