Asynchronously open a directory for iterative scanning. See the POSIX opendir(3) documentation for more detail.
opendir(3)
Creates an fs.Dir, which contains all further functions for reading from and cleaning up the directory.
fs.Dir
The encoding option sets the encoding for the path while opening the directory and subsequent read operations.
encoding
path
Example using async iteration:
import { opendir } from 'fs/promises';try { const dir = await opendir('./'); for await (const dirent of dir) console.log(dirent.name);} catch (err) { console.error(err);} Copy
import { opendir } from '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.
Optional
Fulfills with an {fs.Dir}.
v12.12.0
Generated using TypeDoc
Asynchronously open a directory for iterative scanning. See the POSIX
opendir(3)
documentation for more detail.Creates an
fs.Dir
, which contains all further functions for reading from and cleaning up the directory.The
encoding
option sets the encoding for thepath
while opening the directory and subsequent read operations.Example using async iteration:
When using the async iterator, the
fs.Dir
object will be automatically closed after the iterator exits.