// acquire a FileSystemDirectoryHandle
const handle = await window.showDirectoryPicker();
const fs = new LocalFS(handle);
Get a FileSystemDirectoryHandle
If true, it will recursively create directories
Get a FileSystemFileHandle
Resolves the absolute path of given path or FileSystemHandle
Changes the current working directory
Returns the current working directory
Lists all entries of the specified directory
const fs = new LocalFS(handle);
const allFiles = await fs.ls("/");
const jsFiles = await fs.ls("/", (name, handle)=>name.endsWith(".js"));
const hasPermission = await fs.ls("/", async (name, handle)=>await handle.queryPermission() === "granted");
Optional
filter: (name: string, handle: FileSystemHandle) => boolean | Promise<boolean>a function to filter out entries, can be asynchronous
Overwrites, writes, or appends content to a file.
This method opens a write stream and immediately closes it after writing.
For continuous or large-scale writing, consider writing a buffered writer for better performance.
const fs = new LocalFS(handle);
// overwrite entire file
await fs.write("/file.txt", "Hello World!!!");
// append to end of file
await fs.write("/file.txt", " append this.", {append: true});
// refer to (https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/write#parameters) for clarification
await fs.write("/file.txt", {
type: "write",
position: 6,
data: "LocalFS"
}, {append: false, keepExistingData: true});
refer to FileSystemWriteChunkType
MDN Docs for clarification
Optional
options: { append?: boolean } & FileSystemCreateWritableOptionsOptional
append?: booleanIf true, the content will be appended to the end of the file
If true, the content will be appended to the end of the file
Copy file to destination.
If a file already exists in its destination, it will be overwritten.
const fs = new LocalFS(handle);
await fs.copyFile("/file.txt", "/folder/fileCopy.txt");
Copy directory to destination.
If a directory already exists in its destination, it will be merged and overwritten.
const fs = new LocalFS(handle);
await fs.copyDir("/folder", "/path/to/folder");
A simple FileSystemDirectoryHandle wrapper to easily navigate a local directory with POSIX paths, as well as other functionality for convenience purposes.
All methods accept paths as both
string
, andstring[]
format (acquired throughpath.toArray()
)