Optional
options: CopyFileOptionsCreates a file if none exists or truncates an existing file and resolves to
an instance of FileHandle
.
Optional
options: CreateOptionsCheck if a path exists.
Optional
options: ExistsOptionsResolves 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.
Optional
options: StatOptionsCreates a new directory with the specified path.
Optional
options: MkdirOptionsReads the directory given by path and returns an array of DirEntry
.
Optional
options: ReadDirOptionsimport { 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 }))
}
}
}
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.
Optional
options: ReadFileOptionsReads and returns the entire contents of a file as UTF-8 string.
Optional
options: ReadFileOptionsRemoves 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.
Optional
options: RemoveOptionsRenames (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.
Optional
options: RenameOptionsResolves 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.
Optional
options: StatOptionsTruncates or extends the specified file, to reach the specified len
.
If len
is 0
or not specified, then the entire file contents are truncated.
Optional
len: numberOptional
options: TruncateOptionsimport { truncate, readTextFile, writeTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
// truncate the entire file
await truncate("my_file.txt", 0, { baseDir: BaseDirectory.AppLocalData });
// truncate part of the file
const 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"
Write data
to the given path
, by default creating a new file if needed, else overwriting.
Optional
options: WriteFileOptionsWrites UTF-8 string data
to the given path
, by default creating a new file if needed, else overwriting.
Optional
options: WriteFileOptions
Copies the contents and permissions of one file to another specified path, by default creating a new file if needed, else overwriting.