Dir
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);
}
Content copied to clipboard
When using the async iterator, the fs.Dir
object will be automatically closed after the iterator exits.
Since
v12.12.0
Properties
Functions
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Asynchronously read the next directory entry via readdir(3)
as an fs.Dirent
.
Link copied to clipboard
Synchronously read the next directory entry as an fs.Dirent
. See the POSIX readdir(3)
documentation for more detail.