File System
Access the file system.
Supported Platforms
- Windows
- Linux
- macOS
Setup
This plugin requires a Rust version of at least 1.75
Install the fs plugin to get started.
Use your project’s package manager to add the dependency:
npm run tauri add fsyarn run tauri add fspnpm tauri add fsbun tauri add fscargo tauri add fs-
Install the fs plugin by adding the following to your
Cargo.tomlfile:src-tauri/Cargo.toml [dependencies]tauri-plugin-fs = "2.0.0-beta"# alternatively with Git:tauri-plugin-fs = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } -
Modify
lib.rsto initialize the plugin:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]fn run() {tauri::Builder::default().plugin(tauri_plugin_fs::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
Install the JavaScript Guest bindings using your preferred JavaScript package manager:
npm install @tauri-apps/plugin-fsyarn add @tauri-apps/plugin-fspnpm add @tauri-apps/plugin-fsbun add @tauri-apps/plugin-fs
Usage
The fs plugin is available in both JavaScript and Rust.
import { exists, BaseDirectory } from '@tauri-apps/plugin-fs';// when using `"withGlobalTauri": true`, you may use// const { exists, BaseDirectory } = window.__TAURI_PLUGIN_FS__;
// Check if the `$APPDATA/avatar.png` file existsawait exists('avatar.png', { baseDir: BaseDirectory.AppData });use tauri_plugin_fs::FsExt;
#[cfg_attr(mobile, tauri::mobile_entry_point)]fn run() { tauri::Builder::default() .plugin(tauri_plugin_fs::init()) .setup(|app| { // allowed the given directory let scope = app.fs_scope(); scope.allow_directory("/path/to/directory", false); dbg!(scope.allowed());
Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}Security
This module prevents path traversal, not allowing absolute paths or parent dir components (i.e. /usr/path/to/file or ../path/to/file paths are not allowed). Paths accessed with this API must be relative to one of the base directories so if you need access to arbitrary file system paths, you must write such logic on the core layer instead.
See @tauri-apps/plugin-fs - Security for more information.
Permissions
By default all plugin commands are blocked and cannot be accessed. You must define a list of permissions in your capabilities configuration.
See Permissions Overview for more information.
{ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": [ "fs:default", { "identifier": "fs:allow-exists", "allow": [{ "path": "$APPDATA/*" }] } ]}Default Permission
This set of permissions describes the what kind of
file system access the fs plugin has enabled or denied by default.
Granted Permissions
This default permission set enables read access to the application specific directories (AppConfig, AppData, AppLocalData, AppCache, AppLog) and all files and sub directories created in it. The location of these directories depends on the operating system, where the application is run.
In general these directories need to be manually created by the application at runtime, before accessing files or folders in it is possible.
Therefore, it is also allowed to create all of these folders via
the mkdir command.
Denied Permissions
This default permission set prevents access to critical components of the Tauri application by default. On Windows the webview data folder access is denied.
create-app-specific-dirsread-app-specific-dirs-recursivedeny-default
Permission Table
| Identifier | Description |
|---|---|
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
This allows full recursive read access to the complete |
|
|
This allows full recursive write access to the complete |
|
|
This allows non-recursive read access to the |
|
|
This allows non-recursive write access to the |
|
|
This allows full recursive read access to metadata of the |
|
|
This allows non-recursive read access to metadata of the |
|
|
This scope permits recursive access to the complete |
|
|
This scope permits access to all files and list content of top level directories in the |
|
|
This scope permits to list all files and folders in the |
|
|
Enables the copy_file command without any pre-configured scope. |
|
|
Denies the copy_file command without any pre-configured scope. |
|
|
Enables the create command without any pre-configured scope. |
|
|
Denies the create command without any pre-configured scope. |
|
|
Enables the exists command without any pre-configured scope. |
|
|
Denies the exists command without any pre-configured scope. |
|
|
Enables the fstat command without any pre-configured scope. |
|
|
Denies the fstat command without any pre-configured scope. |
|
|
Enables the ftruncate command without any pre-configured scope. |
|
|
Denies the ftruncate command without any pre-configured scope. |
|
|
Enables the lstat command without any pre-configured scope. |
|
|
Denies the lstat command without any pre-configured scope. |
|
|
Enables the mkdir command without any pre-configured scope. |
|
|
Denies the mkdir command without any pre-configured scope. |
|
|
Enables the open command without any pre-configured scope. |
|
|
Denies the open command without any pre-configured scope. |
|
|
Enables the read command without any pre-configured scope. |
|
|
Denies the read command without any pre-configured scope. |
|
|
Enables the read_dir command without any pre-configured scope. |
|
|
Denies the read_dir command without any pre-configured scope. |
|
|
Enables the read_file command without any pre-configured scope. |
|
|
Denies the read_file command without any pre-configured scope. |
|
|
Enables the read_text_file command without any pre-configured scope. |
|
|
Denies the read_text_file command without any pre-configured scope. |
|
|
Enables the read_text_file_lines command without any pre-configured scope. |
|
|
Denies the read_text_file_lines command without any pre-configured scope. |
|
|
Enables the read_text_file_lines_next command without any pre-configured scope. |
|
|
Denies the read_text_file_lines_next command without any pre-configured scope. |
|
|
Enables the remove command without any pre-configured scope. |
|
|
Denies the remove command without any pre-configured scope. |
|
|
Enables the rename command without any pre-configured scope. |
|
|
Denies the rename command without any pre-configured scope. |
|
|
Enables the seek command without any pre-configured scope. |
|
|
Denies the seek command without any pre-configured scope. |
|
|
Enables the stat command without any pre-configured scope. |
|
|
Denies the stat command without any pre-configured scope. |
|
|
Enables the truncate command without any pre-configured scope. |
|
|
Denies the truncate command without any pre-configured scope. |
|
|
Enables the unwatch command without any pre-configured scope. |
|
|
Denies the unwatch command without any pre-configured scope. |
|
|
Enables the watch command without any pre-configured scope. |
|
|
Denies the watch command without any pre-configured scope. |
|
|
Enables the write command without any pre-configured scope. |
|
|
Denies the write command without any pre-configured scope. |
|
|
Enables the write_file command without any pre-configured scope. |
|
|
Denies the write_file command without any pre-configured scope. |
|
|
Enables the write_text_file command without any pre-configured scope. |
|
|
Denies the write_text_file command without any pre-configured scope. |
|
|
This permissions allows to create the application specific directories. |
|
|
This denies access to dangerous Tauri relevant files and folders by default. |
|
|
This denies read access to the
|
|
|
This denies read access to the
|
|
|
This enables all read related commands without any pre-configured accessible paths. |
|
|
This permission allows recursive read functionality on the application specific base directories. |
|
|
This enables directory read and file metadata related commands without any pre-configured accessible paths. |
|
|
This enables file read related commands without any pre-configured accessible paths. |
|
|
This enables all index or metadata related commands without any pre-configured accessible paths. |
|
|
An empty permission you can use to modify the global scope. |
|
|
This enables all write related commands without any pre-configured accessible paths. |
|
|
This enables all file write related commands without any pre-configured accessible paths. |
Scopes
To allow any fs command to access specific scopes:
{ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": [ { "identifier": "fs:scope", "allow": [{ "path": "$APPDATA" }, { "path": "$APPDATA/**" }] } ]}To allow specific fs command to access specific scopes:
{ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": [ { "identifier": "fs:allow-rename", "allow": [{ "path": "$HOME/**" }] }, { "identifier": "fs:allow-exists", "allow": [{ "path": "$APPDATA/*" }] } ]}© 2024 Tauri Contributors. CC-BY / MIT