@tauri-apps/plugin-fs
Access the file system.
iOS security-scoped resources
Section titled “iOS security-scoped resources”On iOS, the fs plugin automatically manages access to security-scoped resources when a file URL is accessed.
This is required for files outside the app’s sandbox (e.g., from file picker).
Example
Section titled “Example”import { open } from '@tauri-apps/plugin-fs';
const file = await open('file:///path/to/file.txt');await file.close();Security
Section titled “Security”This module prevents path traversal, not allowing parent directory accessors to be used (i.e. “/usr/path/to/../file” or “../path/to/file” paths are not allowed). Paths accessed with this API must be either relative to one of the base directories or created with the path API.
The API has a scope configuration that forces you to restrict the paths that can be accessed using glob patterns.
The scope configuration is an array of glob patterns describing file/directory paths that are allowed.
For instance, this scope configuration allows all enabled fs APIs to (only) access files in the
databases directory of the $APPDATA directory:
{ "permissions": [ { "identifier": "fs:scope", "allow": [{ "path": "$APPDATA/databases/*" }] } ]}Scopes can also be applied to specific fs APIs by using the API’s identifier instead of fs:scope:
{ "permissions": [ { "identifier": "fs:allow-exists", "allow": [{ "path": "$APPDATA/databases/*" }] } ]}Notice the use of the $APPDATA variable. The value is injected at runtime, resolving to the app data directory.
The available variables are:
$APPCONFIG,
$APPDATA,
$APPLOCALDATA,
$APPCACHE,
$APPLOG,
$AUDIO,
$CACHE,
$CONFIG,
$DATA,
$LOCALDATA,
$DESKTOP,
$DOCUMENT,
$DOWNLOAD,
$EXE,
$FONT,
$HOME,
$PICTURE,
$PUBLIC,
$RUNTIME,
$TEMPLATE,
$VIDEO,
$RESOURCE,
$TEMP.
Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.
Enumerations
Section titled “Enumerations”BaseDirectory
Section titled “BaseDirectory”Defined in: @tauri-apps/api/path.d.ts:4
2.0.0
Enumeration Members
Section titled “Enumeration Members”AppCache
Section titled “AppCache”AppCache: 16;Defined in: @tauri-apps/api/path.d.ts:68
appCacheDir for more information.
AppConfig
Section titled “AppConfig”AppConfig: 13;Defined in: @tauri-apps/api/path.d.ts:56
appConfigDir for more information.
AppData
Section titled “AppData”AppData: 14;Defined in: @tauri-apps/api/path.d.ts:60
appDataDir for more information.
AppLocalData
Section titled “AppLocalData”AppLocalData: 15;Defined in: @tauri-apps/api/path.d.ts:64
appLocalDataDir for more information.
AppLog
Section titled “AppLog”AppLog: 17;Defined in: @tauri-apps/api/path.d.ts:72
appLogDir for more information.
Audio: 1;Defined in: @tauri-apps/api/path.d.ts:8
audioDir for more information.
Cache: 2;Defined in: @tauri-apps/api/path.d.ts:12
cacheDir for more information.
Config
Section titled “Config”Config: 3;Defined in: @tauri-apps/api/path.d.ts:16
configDir for more information.
Data: 4;Defined in: @tauri-apps/api/path.d.ts:20
dataDir for more information.
Desktop
Section titled “Desktop”Desktop: 18;Defined in: @tauri-apps/api/path.d.ts:76
desktopDir for more information.
Document
Section titled “Document”Document: 6;Defined in: @tauri-apps/api/path.d.ts:28
documentDir for more information.
Download
Section titled “Download”Download: 7;Defined in: @tauri-apps/api/path.d.ts:32
downloadDir for more information.
Executable
Section titled “Executable”Executable: 19;Defined in: @tauri-apps/api/path.d.ts:80
executableDir for more information.
Font: 20;Defined in: @tauri-apps/api/path.d.ts:84
fontDir for more information.
Home: 21;Defined in: @tauri-apps/api/path.d.ts:88
homeDir for more information.
LocalData
Section titled “LocalData”LocalData: 5;Defined in: @tauri-apps/api/path.d.ts:24
localDataDir for more information.
Picture
Section titled “Picture”Picture: 8;Defined in: @tauri-apps/api/path.d.ts:36
pictureDir for more information.
Public
Section titled “Public”Public: 9;Defined in: @tauri-apps/api/path.d.ts:40
publicDir for more information.
Resource
Section titled “Resource”Resource: 11;Defined in: @tauri-apps/api/path.d.ts:48
resourceDir for more information.
Runtime
Section titled “Runtime”Runtime: 22;Defined in: @tauri-apps/api/path.d.ts:92
runtimeDir for more information.
Temp: 12;Defined in: @tauri-apps/api/path.d.ts:52
tempDir for more information.
Template
Section titled “Template”Template: 23;Defined in: @tauri-apps/api/path.d.ts:96
templateDir for more information.
Video: 10;Defined in: @tauri-apps/api/path.d.ts:44
videoDir for more information.
SeekMode
Section titled “SeekMode”Defined in: plugins/fs/guest-js/index.ts:91
Enumeration Members
Section titled “Enumeration Members”Current
Section titled “Current”Current: 1;Defined in: plugins/fs/guest-js/index.ts:93
End: 2;Defined in: plugins/fs/guest-js/index.ts:94
Start: 0;Defined in: plugins/fs/guest-js/index.ts:92
Classes
Section titled “Classes”FileHandle
Section titled “FileHandle”Defined in: plugins/fs/guest-js/index.ts:295
The Tauri abstraction for reading and writing files.
2.0.0
Extends
Section titled “Extends”Resource
Constructors
Section titled “Constructors”new FileHandle()
Section titled “new FileHandle()”new FileHandle(rid): FileHandle;Defined in: @tauri-apps/api/core.d.ts:184
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
rid |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Resource.constructorAccessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get rid(): number;Defined in: @tauri-apps/api/core.d.ts:183
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Resource.ridMethods
Section titled “Methods”close()
Section titled “close()”close(): Promise<void>;Defined in: @tauri-apps/api/core.d.ts:189
Destroys and cleans up this resource from memory. You should not call any method on this object anymore and should drop any reference to it.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Resource.closeread()
Section titled “read()”read(buffer): Promise<number | null>;Defined in: plugins/fs/guest-js/index.ts:327
Reads up to p.byteLength bytes into p. It resolves to the number of
bytes read (0 < n <= p.byteLength) and rejects if any error
encountered. Even if read() resolves to n < p.byteLength, it may
use all of p as scratch space during the call. If some data is
available but not p.byteLength bytes, read() conventionally resolves
to what is available instead of waiting for more.
When read() encounters end-of-file condition, it resolves to EOF
(null).
When read() encounters an error, it rejects with an error.
Callers should always process the n > 0 bytes returned before
considering the EOF (null). Doing so correctly handles I/O errors that
happen after reading some bytes and also both of the allowed EOF
behaviors.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
buffer |
Uint8Array |
Returns
Section titled “Returns”Promise<number | null>
Example
Section titled “Example”import { open, BaseDirectory } from "@tauri-apps/plugin-fs"// if "$APPCONFIG/foo/bar.txt" contains the text "hello world":const file = await open("foo/bar.txt", { baseDir: BaseDirectory.AppConfig });const buf = new Uint8Array(100);const numberOfBytesRead = await file.read(buf); // 11 bytesconst text = new TextDecoder().decode(buf); // "hello world"await file.close();2.0.0
seek()
Section titled “seek()”seek(offset, whence): Promise<number>;Defined in: plugins/fs/guest-js/index.ts:382
Seek sets the offset for the next read() or write() to offset,
interpreted according to whence: Start means relative to the
start of the file, Current means relative to the current offset,
and End means relative to the end. Seek resolves to the new offset
relative to the start of the file.
Seeking to an offset before the start of the file is an error. Seeking to any positive offset is legal, but the behavior of subsequent I/O operations on the underlying object is implementation-dependent. It returns the number of cursor position.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
offset |
number |
whence |
SeekMode |
Returns
Section titled “Returns”Example
Section titled “Example”import { open, SeekMode, BaseDirectory } from '@tauri-apps/plugin-fs';
// Given hello.txt pointing to file with "Hello world", which is 11 bytes long:const file = await open('hello.txt', { read: true, write: true, truncate: true, create: true, baseDir: BaseDirectory.AppLocalData });await file.write(new TextEncoder().encode("Hello world"));
// Seek 6 bytes from the start of the fileconsole.log(await file.seek(6, SeekMode.Start)); // "6"// Seek 2 more bytes from the current positionconsole.log(await file.seek(2, SeekMode.Current)); // "8"// Seek backwards 2 bytes from the end of the fileconsole.log(await file.seek(-2, SeekMode.End)); // "9" (e.g. 11-2)
await file.close();2.0.0
stat()
Section titled “stat()”stat(): Promise<FileInfo>;Defined in: plugins/fs/guest-js/index.ts:404
Returns a FileInfo for this file.
Returns
Section titled “Returns”Example
Section titled “Example”import { open, BaseDirectory } from '@tauri-apps/plugin-fs';const file = await open("file.txt", { read: true, baseDir: BaseDirectory.AppLocalData });const fileInfo = await file.stat();console.log(fileInfo.isFile); // trueawait file.close();2.0.0
truncate()
Section titled “truncate()”truncate(len?): Promise<void>;Defined in: plugins/fs/guest-js/index.ts:436
Truncates or extends this file, to reach the specified len.
If len is not specified then the entire file contents are truncated.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
len? |
number |
Returns
Section titled “Returns”Example
Section titled “Example”import { open, BaseDirectory } from '@tauri-apps/plugin-fs';
// truncate the entire fileconst file = await open("my_file.txt", { read: true, write: true, create: true, baseDir: BaseDirectory.AppLocalData });await file.truncate();
// truncate part of the fileconst file = await open("my_file.txt", { read: true, write: true, create: true, baseDir: BaseDirectory.AppLocalData });await file.write(new TextEncoder().encode("Hello World"));await file.truncate(7);const data = new Uint8Array(32);await file.read(data);console.log(new TextDecoder().decode(data)); // Hello Wawait file.close();2.0.0
write()
Section titled “write()”write(data): Promise<number>;Defined in: plugins/fs/guest-js/index.ts:463
Writes data.byteLength bytes from data to the underlying data stream. It
resolves to the number of bytes written from data (0 <= n <=
data.byteLength) or reject with the error encountered that caused the
write to stop early. write() must reject with a non-null error if
would resolve to n < data.byteLength. write() must not modify the
slice data, even temporarily.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data |
Uint8Array |
Returns
Section titled “Returns”Example
Section titled “Example”import { open, write, BaseDirectory } from '@tauri-apps/plugin-fs';const encoder = new TextEncoder();const data = encoder.encode("Hello world");const file = await open("bar.txt", { write: true, baseDir: BaseDirectory.AppLocalData });const bytesWritten = await file.write(data); // 11await file.close();2.0.0
Interfaces
Section titled “Interfaces”CopyFileOptions
Section titled “CopyFileOptions”Defined in: plugins/fs/guest-js/index.ts:597
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
fromPathBaseDir? |
BaseDirectory |
Base directory for fromPath. |
plugins/fs/guest-js/index.ts:599 |
toPathBaseDir? |
BaseDirectory |
Base directory for toPath. |
plugins/fs/guest-js/index.ts:601 |
CreateOptions
Section titled “CreateOptions”Defined in: plugins/fs/guest-js/index.ts:474
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
baseDir? |
BaseDirectory |
Base directory for path |
plugins/fs/guest-js/index.ts:476 |
DebouncedWatchOptions
Section titled “DebouncedWatchOptions”Defined in: plugins/fs/guest-js/index.ts:1201
2.0.0
Extends
Section titled “Extends”Properties
Section titled “Properties”| Property | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|
baseDir? |
BaseDirectory |
Base directory for path |
WatchOptions.baseDir |
plugins/fs/guest-js/index.ts:1195 |
delayMs? |
number |
Debounce delay | - | plugins/fs/guest-js/index.ts:1203 |
recursive? |
boolean |
Watch a directory recursively | WatchOptions.recursive |
plugins/fs/guest-js/index.ts:1193 |
DirEntry
Section titled “DirEntry”Defined in: plugins/fs/guest-js/index.ts:686
A disk entry which is either a file, a directory or a symlink.
This is the result of the readDir.
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
isDirectory |
boolean |
Specifies whether this entry is a directory or not. | plugins/fs/guest-js/index.ts:690 |
isFile |
boolean |
Specifies whether this entry is a file or not. | plugins/fs/guest-js/index.ts:692 |
isSymlink |
boolean |
Specifies whether this entry is a symlink or not. | plugins/fs/guest-js/index.ts:694 |
name |
string |
The name of the entry (file name with extension or directory name). | plugins/fs/guest-js/index.ts:688 |
ExistsOptions
Section titled “ExistsOptions”Defined in: plugins/fs/guest-js/index.ts:1158
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
baseDir? |
BaseDirectory |
Base directory for path. |
plugins/fs/guest-js/index.ts:1160 |
FileInfo
Section titled “FileInfo”Defined in: plugins/fs/guest-js/index.ts:102
A FileInfo describes a file and is returned by stat, lstat or fstat.
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
atime |
| Date | null |
The last access time of the file. This corresponds to the atime field from stat on Unix and ftLastAccessTime on Windows. This may not be available on all platforms. |
plugins/fs/guest-js/index.ts:133 |
birthtime |
| Date | null |
The creation time of the file. This corresponds to the birthtime field from stat on Mac/BSD and ftCreationTime on Windows. This may not be available on all platforms. |
plugins/fs/guest-js/index.ts:139 |
blksize |
number | null |
Blocksize for filesystem I/O. Platform-specific - Windows: Unsupported. | plugins/fs/guest-js/index.ts:216 |
blocks |
number | null |
Number of blocks allocated to the file, in 512-byte units. Platform-specific - Windows: Unsupported. | plugins/fs/guest-js/index.ts:224 |
dev |
number | null |
ID of the device containing the file. Platform-specific - Windows: Unsupported. | plugins/fs/guest-js/index.ts:159 |
fileAttributes |
number | null |
This field contains the file system attribute information for a file or directory. For possible values and their descriptions, see File Attribute Constants in the Windows Dev Center Platform-specific - macOS / Linux / Android / iOS: Unsupported. | plugins/fs/guest-js/index.ts:151 |
gid |
number | null |
Group ID of the owner of this file. Platform-specific - Windows: Unsupported. | plugins/fs/guest-js/index.ts:200 |
ino |
number | null |
Inode number. Platform-specific - Windows: Unsupported. | plugins/fs/guest-js/index.ts:167 |
isDirectory |
boolean |
True if this is info for a regular directory. Mutually exclusive to FileInfo.isFile and FileInfo.isSymlink. |
plugins/fs/guest-js/index.ts:112 |
isFile |
boolean |
True if this is info for a regular file. Mutually exclusive to FileInfo.isDirectory and FileInfo.isSymlink. |
plugins/fs/guest-js/index.ts:107 |
isSymlink |
boolean |
True if this is info for a symlink. Mutually exclusive to FileInfo.isFile and FileInfo.isDirectory. |
plugins/fs/guest-js/index.ts:117 |
mode |
number | null |
The underlying raw st_mode bits that contain the standard Unix permissions for this file/directory. Platform-specific - Windows: Unsupported. |
plugins/fs/guest-js/index.ts:176 |
mtime |
| Date | null |
The last modification time of the file. This corresponds to the mtime field from stat on Linux/Mac OS and ftLastWriteTime on Windows. This may not be available on all platforms. |
plugins/fs/guest-js/index.ts:127 |
nlink |
number | null |
Number of hard links pointing to this file. Platform-specific - Windows: Unsupported. | plugins/fs/guest-js/index.ts:184 |
rdev |
number | null |
Device ID of this file. Platform-specific - Windows: Unsupported. | plugins/fs/guest-js/index.ts:208 |
readonly |
boolean |
Whether this is a readonly (unwritable) file. | plugins/fs/guest-js/index.ts:141 |
size |
number |
The size of the file, in bytes. | plugins/fs/guest-js/index.ts:121 |
uid |
number | null |
User ID of the owner of this file. Platform-specific - Windows: Unsupported. | plugins/fs/guest-js/index.ts:192 |
MkdirOptions
Section titled “MkdirOptions”Defined in: plugins/fs/guest-js/index.ts:636
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
baseDir? |
BaseDirectory |
Base directory for path |
plugins/fs/guest-js/index.ts:644 |
mode? |
number |
Permissions to use when creating the directory (defaults to 0o777, before the process’s umask). Ignored on Windows. |
plugins/fs/guest-js/index.ts:638 |
recursive? |
boolean |
Defaults to false. If set to true, means that any intermediate directories will also be created (as with the shell command mkdir -p). |
plugins/fs/guest-js/index.ts:642 |
OpenOptions
Section titled “OpenOptions”Defined in: plugins/fs/guest-js/index.ts:512
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
append? |
boolean |
Sets the option for the append mode. This option, when true, means that writes will append to a file instead of overwriting previous contents. Note that setting { write: true, append: true } has the same effect as setting only { append: true }. |
plugins/fs/guest-js/index.ts:531 |
baseDir? |
BaseDirectory |
Base directory for path |
plugins/fs/guest-js/index.ts:559 |
create? |
boolean |
Sets the option to allow creating a new file, if one doesn’t already exist at the specified path. Requires write or append access to be used. | plugins/fs/guest-js/index.ts:544 |
createNew? |
boolean |
Defaults to false. If set to true, no file, directory, or symlink is allowed to exist at the target location. Requires write or append access to be used. When createNew is set to true, create and truncate are ignored. |
plugins/fs/guest-js/index.ts:551 |
mode? |
number |
Permissions to use if creating the file (defaults to 0o666, before the process’s umask). Ignored on Windows. |
plugins/fs/guest-js/index.ts:557 |
read? |
boolean |
Sets the option for read access. This option, when true, means that the file should be read-able if opened. |
plugins/fs/guest-js/index.ts:517 |
truncate? |
boolean |
Sets the option for truncating a previous file. If a file is successfully opened with this option set it will truncate the file to 0 size if it already exists. The file must be opened with write access for truncate to work. |
plugins/fs/guest-js/index.ts:538 |
write? |
boolean |
Sets the option for write access. This option, when true, means that the file should be write-able if opened. If the file already exists, any write calls on it will overwrite its contents, by default without truncating it. |
plugins/fs/guest-js/index.ts:524 |
ReadDirOptions
Section titled “ReadDirOptions”Defined in: plugins/fs/guest-js/index.ts:674
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
baseDir? |
BaseDirectory |
Base directory for path |
plugins/fs/guest-js/index.ts:676 |
ReadFileOptions
Section titled “ReadFileOptions”Defined in: plugins/fs/guest-js/index.ts:736
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
baseDir? |
BaseDirectory |
Base directory for path |
plugins/fs/guest-js/index.ts:738 |
encoding? |
string |
Text encoding to use when reading a text file. Defaults to ‘utf-8’. | plugins/fs/guest-js/index.ts:740 |
RemoveOptions
Section titled “RemoveOptions”Defined in: plugins/fs/guest-js/index.ts:878
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
baseDir? |
BaseDirectory |
Base directory for path |
plugins/fs/guest-js/index.ts:882 |
recursive? |
boolean |
Defaults to false. If set to true, path will be removed even if it’s a non-empty directory. |
plugins/fs/guest-js/index.ts:880 |
RenameOptions
Section titled “RenameOptions”Defined in: plugins/fs/guest-js/index.ts:914
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
newPathBaseDir? |
BaseDirectory |
Base directory for newPath. |
plugins/fs/guest-js/index.ts:918 |
oldPathBaseDir? |
BaseDirectory |
Base directory for oldPath. |
plugins/fs/guest-js/index.ts:916 |
StatOptions
Section titled “StatOptions”Defined in: plugins/fs/guest-js/index.ts:958
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
baseDir? |
BaseDirectory |
Base directory for path. |
plugins/fs/guest-js/index.ts:960 |
TruncateOptions
Section titled “TruncateOptions”Defined in: plugins/fs/guest-js/index.ts:1017
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
baseDir? |
BaseDirectory |
Base directory for path. |
plugins/fs/guest-js/index.ts:1019 |
WatchEvent
Section titled “WatchEvent”Defined in: plugins/fs/guest-js/index.ts:1209
2.0.0
Properties
Section titled “Properties”| Property | Type | Defined in |
|---|---|---|
attrs |
unknown |
plugins/fs/guest-js/index.ts:1212 |
paths |
string[] |
plugins/fs/guest-js/index.ts:1211 |
type |
WatchEventKind |
plugins/fs/guest-js/index.ts:1210 |
WatchOptions
Section titled “WatchOptions”Defined in: plugins/fs/guest-js/index.ts:1191
2.0.0
Extended by
Section titled “Extended by”Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
baseDir? |
BaseDirectory |
Base directory for path |
plugins/fs/guest-js/index.ts:1195 |
recursive? |
boolean |
Watch a directory recursively | plugins/fs/guest-js/index.ts:1193 |
WriteFileOptions
Section titled “WriteFileOptions”Defined in: plugins/fs/guest-js/index.ts:1061
2.0.0
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
append? |
boolean |
Defaults to false. If set to true, will append to a file instead of overwriting previous contents. |
plugins/fs/guest-js/index.ts:1063 |
baseDir? |
BaseDirectory |
Base directory for path |
plugins/fs/guest-js/index.ts:1071 |
create? |
boolean |
Sets the option to allow creating a new file, if one doesn’t already exist at the specified path (defaults to true). |
plugins/fs/guest-js/index.ts:1065 |
createNew? |
boolean |
Sets the option to create a new file, failing if it already exists. | plugins/fs/guest-js/index.ts:1067 |
mode? |
number |
File permissions. Ignored on Windows. | plugins/fs/guest-js/index.ts:1069 |
Type Aliases
Section titled “Type Aliases”UnwatchFn
Section titled “UnwatchFn”type UnwatchFn = () => void;Defined in: plugins/fs/guest-js/index.ts:1277
Returns
Section titled “Returns”void
2.0.0
WatchEventKind
Section titled “WatchEventKind”type WatchEventKind = | "any" | { access: WatchEventKindAccess;} | { create: WatchEventKindCreate;} | { modify: WatchEventKindModify;} | { remove: WatchEventKindRemove;} | "other";Defined in: plugins/fs/guest-js/index.ts:1218
2.0.0
WatchEventKindAccess
Section titled “WatchEventKindAccess”type WatchEventKindAccess = | { kind: "any";} | { kind: "close"; mode: "any" | "execute" | "read" | "write" | "other";} | { kind: "open"; mode: "any" | "execute" | "read" | "write" | "other";} | { kind: "other";};Defined in: plugins/fs/guest-js/index.ts:1229
2.0.0
WatchEventKindCreate
Section titled “WatchEventKindCreate”type WatchEventKindCreate = | { kind: "any";} | { kind: "file";} | { kind: "folder";} | { kind: "other";};Defined in: plugins/fs/guest-js/index.ts:1238
2.0.0
WatchEventKindModify
Section titled “WatchEventKindModify”type WatchEventKindModify = | { kind: "any";} | { kind: "data"; mode: "any" | "size" | "content" | "other";} | { kind: "metadata"; mode: | "any" | "access-time" | "write-time" | "permissions" | "ownership" | "extended" | "other";} | { kind: "rename"; mode: "any" | "to" | "from" | "both" | "other";} | { kind: "other";};Defined in: plugins/fs/guest-js/index.ts:1247
2.0.0
WatchEventKindRemove
Section titled “WatchEventKindRemove”type WatchEventKindRemove = | { kind: "any";} | { kind: "file";} | { kind: "folder";} | { kind: "other";};Defined in: plugins/fs/guest-js/index.ts:1267
2.0.0
Functions
Section titled “Functions”copyFile()
Section titled “copyFile()”function copyFile( fromPath, toPath,options?): Promise<void>;Defined in: plugins/fs/guest-js/index.ts:614
Copies the contents and permissions of one file to another specified path, by default creating a new file if needed, else overwriting.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fromPath |
string | URL |
toPath |
string | URL |
options? |
CopyFileOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { copyFile, BaseDirectory } from '@tauri-apps/plugin-fs';await copyFile('app.conf', 'app.conf.bk', { fromPathBaseDir: BaseDirectory.AppConfig, toPathBaseDir: BaseDirectory.AppConfig });2.0.0
create()
Section titled “create()”function create(path, options?): Promise<FileHandle>;Defined in: plugins/fs/guest-js/index.ts:493
Creates a file if none exists or truncates an existing file and resolves to
an instance of FileHandle.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
options? |
CreateOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { create, BaseDirectory } from "@tauri-apps/plugin-fs"const file = await create("foo/bar.txt", { baseDir: BaseDirectory.AppConfig });await file.write(new TextEncoder().encode("Hello world"));await file.close();2.0.0
exists()
Section titled “exists()”function exists(path, options?): Promise<boolean>;Defined in: plugins/fs/guest-js/index.ts:1174
Check if a path exists.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
options? |
ExistsOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { exists, BaseDirectory } from '@tauri-apps/plugin-fs';// Check if the `$APPDATA/avatar.png` file existsawait exists('avatar.png', { baseDir: BaseDirectory.AppData });2.0.0
lstat()
Section titled “lstat()”function lstat(path, options?): Promise<FileInfo>;Defined in: plugins/fs/guest-js/index.ts:1002
Resolves to a FileInfo for the specified path. If path is a
symlink, information for the symlink will be returned instead of what it
points to.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
options? |
StatOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { lstat, BaseDirectory } from '@tauri-apps/plugin-fs';const fileInfo = await lstat("hello.txt", { baseDir: BaseDirectory.AppLocalData });console.log(fileInfo.isFile); // true2.0.0
mkdir()
Section titled “mkdir()”function mkdir(path, options?): Promise<void>;Defined in: plugins/fs/guest-js/index.ts:657
Creates a new directory with the specified path.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
options? |
MkdirOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { mkdir, BaseDirectory } from '@tauri-apps/plugin-fs';await mkdir('users', { baseDir: BaseDirectory.AppLocalData });2.0.0
open()
Section titled “open()”function open(path, options?): Promise<FileHandle>;Defined in: plugins/fs/guest-js/index.ts:578
Open a file and resolve to an instance of FileHandle. The
file does not need to previously exist if using the create or createNew
open options. It is the callers responsibility to close the file when finished
with it.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
options? |
OpenOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { open, BaseDirectory } from "@tauri-apps/plugin-fs"const file = await open("foo/bar.txt", { read: true, write: true, baseDir: BaseDirectory.AppLocalData });// Do work with fileawait file.close();2.0.0
readDir()
Section titled “readDir()”function readDir(path, options?): Promise<DirEntry[]>;Defined in: plugins/fs/guest-js/index.ts:719
Reads the directory given by path and returns an array of DirEntry.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
options? |
ReadDirOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { readDir, BaseDirectory } from '@tauri-apps/plugin-fs';import { join } from '@tauri-apps/api/path';const dir = "users"const entries = await readDir('users', { baseDir: BaseDirectory.AppLocalData });processEntriesRecursively(dir, entries);async function processEntriesRecursively(parent, entries) { for (const entry of entries) { console.log(`Entry: ${entry.name}`); if (entry.isDirectory) { const dir = await join(parent, entry.name); processEntriesRecursively(dir, await readDir(dir, { baseDir: BaseDirectory.AppLocalData })) } }}2.0.0
readFile()
Section titled “readFile()”function readFile(path, options?): Promise<any>;Defined in: plugins/fs/guest-js/index.ts:754
Reads and resolves to the entire contents of a file as an array of bytes. TextDecoder can be used to transform the bytes to string if required.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
options? |
ReadFileOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { readFile, BaseDirectory } from '@tauri-apps/plugin-fs';const contents = await readFile('avatar.png', { baseDir: BaseDirectory.Resource });2.0.0
readTextFile()
Section titled “readTextFile()”function readTextFile(path, options?): Promise<string>;Defined in: plugins/fs/guest-js/index.ts:780
Reads and returns the entire contents of a file as a string using the specified encoding (default: UTF-8).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
options? |
ReadFileOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { readTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';const contents = await readTextFile('app.conf', { baseDir: BaseDirectory.AppConfig });2.0.0
readTextFileLines()
Section titled “readTextFileLines()”function readTextFileLines(path, options?): Promise<AsyncIterableIterator<string>>;Defined in: plugins/fs/guest-js/index.ts:813
Returns an async AsyncIterableIterator over the lines of a file, decoded using the specified encoding (default: UTF-8).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
options? |
ReadFileOptions |
Returns
Section titled “Returns”Promise<AsyncIterableIterator<string>>
Example
Section titled “Example”import { readTextFileLines, BaseDirectory } from '@tauri-apps/plugin-fs';const lines = await readTextFileLines('app.conf', { baseDir: BaseDirectory.AppConfig });for await (const line of lines) { console.log(line);}You could also call AsyncIterableIterator.next to advance the
iterator so you can lazily read the next line whenever you want.
2.0.0
remove()
Section titled “remove()”function remove(path, options?): Promise<void>;Defined in: plugins/fs/guest-js/index.ts:897
Removes the named file or directory.
If the directory is not empty and the recursive option isn’t set to true, the promise will be rejected.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
options? |
RemoveOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { remove, BaseDirectory } from '@tauri-apps/plugin-fs';await remove('users/file.txt', { baseDir: BaseDirectory.AppLocalData });await remove('users', { baseDir: BaseDirectory.AppLocalData });2.0.0
rename()
Section titled “rename()”function rename( oldPath, newPath,options?): Promise<void>;Defined in: plugins/fs/guest-js/index.ts:936
Renames (moves) oldpath to newpath. Paths may be files or directories. If newpath already exists and is not a directory, rename() replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories.
On Unix, this operation does not follow symlinks at either path.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
oldPath |
string | URL |
newPath |
string | URL |
options? |
RenameOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { rename, BaseDirectory } from '@tauri-apps/plugin-fs';await rename('avatar.png', 'deleted.png', { oldPathBaseDir: BaseDirectory.App, newPathBaseDir: BaseDirectory.AppLocalData });2.0.0
size()
Section titled “size()”function size(path): Promise<number>;Defined in: plugins/fs/guest-js/index.ts:1359
Get the size of a file or directory. For files, the stat functions can be used as well.
If path is a directory, this function will recursively iterate over every file and every directory inside of path and therefore will be very time consuming if used on larger directories.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
Returns
Section titled “Returns”Example
Section titled “Example”import { size, BaseDirectory } from '@tauri-apps/plugin-fs';// Get the size of the `$APPDATA/tauri` directory.const dirSize = await size('tauri', { baseDir: BaseDirectory.AppData });console.log(dirSize); // 10242.1.0
startAccessingSecurityScopedResource()
Section titled “startAccessingSecurityScopedResource()”function startAccessingSecurityScopedResource(path): Promise<void>;Defined in: plugins/fs/guest-js/index.ts:1395
Starts accessing a security-scoped resource for the given file URL. This should be called when you’re accessing a file that was opened using a security-scoped URL (e.g., from a file picker).
Note that accessing security-scoped resources is automatically managed by the plugin on iOS, so you don’t need to call this function unless you want to manage the scope manually.
You must call stopAccessingSecurityScopedResource when you’re done accessing the resource.
Platform-specific
- iOS: Starts accessing the security-scoped resource.
- Other platforms: does nothing.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
Returns
Section titled “Returns”Example
Section titled “Example”import { startAccessingSecurityScopedResource } from '@tauri-apps/plugin-fs';
const filePath = 'file:///path/to/file.txt';await startAccessingSecurityScopedResource(filePath);// ... use the resource ...2.5.0
stat()
Section titled “stat()”function stat(path, options?): Promise<FileInfo>;Defined in: plugins/fs/guest-js/index.ts:976
Resolves to a FileInfo for the specified path. Will always
follow symlinks but will reject if the symlink points to a path outside of the scope.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
options? |
StatOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { stat, BaseDirectory } from '@tauri-apps/plugin-fs';const fileInfo = await stat("hello.txt", { baseDir: BaseDirectory.AppLocalData });console.log(fileInfo.isFile); // true2.0.0
stopAccessingSecurityScopedResource()
Section titled “stopAccessingSecurityScopedResource()”function stopAccessingSecurityScopedResource(path): Promise<void>;Defined in: plugins/fs/guest-js/index.ts:1430
Stops accessing a security-scoped resource for the given file URL.
This should be called when you’re done accessing a file that was opened
using a security-scoped URL (e.g., from a file picker) when using manual tracking via startAccessingSecurityScopedResource.
Platform-specific
- iOS: Stops accessing the security-scoped resource.
- Other platforms: does nothing.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
Returns
Section titled “Returns”Example
Section titled “Example”import { stopAccessingSecurityScopedResource } from '@tauri-apps/plugin-fs';
const filePath = 'file:///path/to/file.txt';await startAccessingSecurityScopedResource(filePath);// ... use the resource ...// when you're done with the resource:await stopAccessingSecurityScopedResource(filePath);2.5.0
truncate()
Section titled “truncate()”function truncate( path, len?,options?): Promise<void>;Defined in: plugins/fs/guest-js/index.ts:1042
Truncates or extends the specified file, to reach the specified len.
If len is 0 or not specified, then the entire file contents are truncated.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
len? |
number |
options? |
TruncateOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { truncate, readTextFile, writeTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';// truncate the entire fileawait truncate("my_file.txt", 0, { baseDir: BaseDirectory.AppLocalData });
// truncate part of the fileconst filePath = "file.txt";await writeTextFile(filePath, "Hello World", { baseDir: BaseDirectory.AppLocalData });await truncate(filePath, 7, { baseDir: BaseDirectory.AppLocalData });const data = await readTextFile(filePath, { baseDir: BaseDirectory.AppLocalData });console.log(data); // "Hello W"2.0.0
watch()
Section titled “watch()”function watch( paths, cb,options?): Promise<UnwatchFn>;Defined in: plugins/fs/guest-js/index.ts:1316
Watch changes (after a delay) on files or directories.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
paths |
| string | string[] | URL | URL[] |
cb |
(event) => void |
options? |
DebouncedWatchOptions |
Returns
Section titled “Returns”2.0.0
watchImmediate()
Section titled “watchImmediate()”function watchImmediate( paths, cb,options?): Promise<UnwatchFn>;Defined in: plugins/fs/guest-js/index.ts:1333
Watch changes on files or directories.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
paths |
| string | string[] | URL | URL[] |
cb |
(event) => void |
options? |
WatchOptions |
Returns
Section titled “Returns”2.0.0
writeFile()
Section titled “writeFile()”function writeFile( path, data,options?): Promise<void>;Defined in: plugins/fs/guest-js/index.ts:1087
Write data to the given path, by default creating a new file if needed, else overwriting.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
data |
| Uint8Array | ReadableStream<Uint8Array> |
options? |
WriteFileOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { writeFile, BaseDirectory } from '@tauri-apps/plugin-fs';
let encoder = new TextEncoder();let data = encoder.encode("Hello World");await writeFile('file.txt', data, { baseDir: BaseDirectory.AppLocalData });2.0.0
writeTextFile()
Section titled “writeTextFile()”function writeTextFile( path, data,options?): Promise<void>;Defined in: plugins/fs/guest-js/index.ts:1136
Writes UTF-8 string data to the given path, by default creating a new file if needed, else overwriting.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | URL |
data |
string |
options? |
WriteFileOptions |
Returns
Section titled “Returns”Example
Section titled “Example”import { writeTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
await writeTextFile('file.txt', "Hello world", { baseDir: BaseDirectory.AppLocalData });2.0.0
© 2026 Tauri Contributors. CC-BY / MIT