Skip to main content

Access the file system.

This package is also accessible with window.__TAURI__.fs when tauri.conf.json > build > withGlobalTauri is set to true.

The APIs must be allowlisted on tauri.conf.json:

{
  "tauri": {
    "allowlist": {
      "fs": {
        "all": true, // enable all FS APIs
        "readTextFile": true,
        "readBinaryFile": true,
        "writeFile": true,
        "writeBinaryFile": true,
        "readDir": true,
        "copyFile": true,
        "createDir": true,
        "removeDir": true,
        "removeFile": true,
        "renameFile": true
      }
    }
  }
}

It is recommended to allowlist only the APIs you use for optimal bundle size and security.

Enumerations#

Interfaces#

References#

Dir#

Renames and exports: BaseDirectory

Functions#

copyFile#

copyFile(source, destination, options?): Promise<void>

Copys a file to a destination.

Parameters#

NameTypeDescription
sourcestringA path of the file to copy.
destinationstringA path for the destination file.
optionsFsOptionsConfiguration object.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Defined in#

fs.ts:300


createDir#

createDir(dir, options?): Promise<void>

Creates a directory. If one of the path's parent components doesn't exist and the recursive option isn't set to true, the promise will be rejected.

Parameters#

NameTypeDescription
dirstringPath to the directory to create.
optionsFsDirOptionsConfiguration object.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Defined in#

fs.ts:256


readBinaryFile#

readBinaryFile(filePath, options?): Promise<number[]>

Reads a file as byte array.

Parameters#

NameTypeDescription
filePathstringPath to the file.
optionsFsOptionsConfiguration object.

Returns#

Promise<number[]>

A promise resolving to the file bytes array.

Defined in#

fs.ts:118


readDir#

readDir(dir, options?): Promise<FileEntry[]>

List directory files.

Parameters#

NameTypeDescription
dirstringPath to the directory to read.
optionsFsDirOptionsConfiguration object.

Returns#

Promise<FileEntry[]>

A promise resolving to the directory entries.

Defined in#

fs.ts:233


readTextFile#

readTextFile(filePath, options?): Promise<string>

Reads a file as UTF-8 encoded string.

Parameters#

NameTypeDescription
filePathstringPath to the file.
optionsFsOptionsConfiguration object.

Returns#

Promise<string>

A promise resolving to the file content as a UTF-8 encoded string.

Defined in#

fs.ts:97


removeDir#

removeDir(dir, options?): Promise<void>

Removes a directory. If the directory is not empty and the recursive option isn't set to true, the promise will be rejected.

Parameters#

NameTypeDescription
dirstringPath to the directory to remove.
optionsFsDirOptionsConfiguration object.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Defined in#

fs.ts:278


removeFile#

removeFile(file, options?): Promise<void>

Removes a file.

Parameters#

NameTypeDescription
filestringPath to the file to remove.
optionsFsOptionsConfiguration object.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Defined in#

fs.ts:323


renameFile#

renameFile(oldPath, newPath, options?): Promise<void>

Renames a file.

Parameters#

NameTypeDescription
oldPathstringA path of the file to rename.
newPathstringA path of the new file name.
optionsFsOptionsConfiguration object.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Defined in#

fs.ts:345


writeBinaryFile#

writeBinaryFile(file, options?): Promise<void>

Writes a binary file.

Parameters#

NameTypeDescription
fileFsBinaryFileOptionWrite configuration object.
optionsFsOptionsConfiguration object.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Defined in#

fs.ts:204


writeFile#

writeFile(file, options?): Promise<void>

Writes a text file.

Parameters#

NameTypeDescription
fileFsTextFileOptionFile configuration object.
optionsFsOptionsConfiguration object.

Returns#

Promise<void>

A promise indicating the success or failure of the operation.

Defined in#

fs.ts:139