readDirectory
Lists the entries in a directory.
Example
ts
import { SF } from "@duplojs/server-utils";
import { E, unwrap } from "@duplojs/utils";
const entries = await SF.readDirectory("/tmp");
// entries: E.Success<string[]> | SF.FileSystemLeft
if (E.isRight(entries)) {
const list = unwrap(entries);
// list: string[]
}
const recursive = await SF.readDirectory("/tmp", { recursive: true });
// recursive: E.Success<string[]> | SF.FileSystemLeftSyntax
typescript
function readDirectory(
path: string | URL,
params?: {
recursive?: true
}
): Promise<FileSystemLeft | E.Success<string[]>>Parameters
path: path of the directory to list.params.recursive: also lists subdirectories iftrue.
Return value
E.Success<string[]>: list of entries.FileSystemLeft: if the read fails.
See also
makeDirectory- Creates a directory.
