Optionaloptions: CopyFileOptionsCreates a file if none exists or truncates an existing file and resolves to
an instance of FileHandle.
Optionaloptions: CreateOptionsCheck if a path exists.
Optionaloptions: 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.
Optionaloptions: StatOptionsCreates a new directory with the specified path.
Optionaloptions: MkdirOptionsReads the directory given by path and returns an array of DirEntry.
Optionaloptions: 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.
Optionaloptions: ReadFileOptionsReads and returns the entire contents of a file as UTF-8 string.
Optionaloptions: 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.
Optionaloptions: 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.
Optionaloptions: 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.
Optionaloptions: 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.
Optionallen: numberOptionaloptions: 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.
Optionaloptions: WriteFileOptionsWrites UTF-8 string data to the given path, by default creating a new file if needed, else overwriting.
Optionaloptions: WriteFileOptions
Copies the contents and permissions of one file to another specified path, by default creating a new file if needed, else overwriting.