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<"read-directory">
if (E.isRight(entries)) {
const list = unwrap(entries);
// list: string[]
}
const recursive = await SF.readDirectory("/tmp", { recursive: true });
// recursive: E.Success<string[]> | SF.FileSystemLeft<"read-directory">Syntax
typescript
function readDirectory(
path: string,
params?: {
recursive?: true
}
): Promise<FileSystemLeft<"read-directory"> | 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<"read-directory">: if the read fails.
See also
makeDirectory- Creates a directory.
