Dir

external class Dir : <ERROR CLASS> ERROR CLASS: Symbol not found for AsyncIterable<node/fs/Dirent<*>>(source)

A class representing a directory stream.

Created by {@link opendir}, {@link opendirSync}, or fsPromises.opendir().

import { opendir } from 'node:fs/promises';

try {
const dir = await opendir('./');
for await (const dirent of dir)
console.log(dirent.name);
} catch (err) {
console.error(err);
}

When using the async iterator, the fs.Dir object will be automatically closed after the iterator exits.

Since

v12.12.0

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The read-only path of this directory as was provided to {@link opendir},{@link opendirSync}, or fsPromises.opendir().

Functions

Link copied to clipboard
suspend fun close(): ERROR CLASS: Symbol not found for js.core.Void
Link copied to clipboard
fun closeAsync(): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for js.core.Void>

Asynchronously close the directory's underlying resource handle. Subsequent reads will result in errors.

Link copied to clipboard
fun closeSync()

Synchronously close the directory's underlying resource handle. Subsequent reads will result in errors.

Link copied to clipboard
suspend fun read(): Dirent<*>?
fun read(cb: (err: ErrnoException?, dirEnt: Dirent<*>?) -> Unit)
Link copied to clipboard
fun readAsync(): ERROR CLASS: Symbol not found for Promise<node/fs/Dirent<*>?>

Asynchronously read the next directory entry via readdir(3) as an fs.Dirent.

Link copied to clipboard
fun readSync(): Dirent<*>?

Synchronously read the next directory entry as an fs.Dirent. See the POSIX readdir(3) documentation for more detail.