Skip to content

Path.iterdir() method

pathlib-ts > Path > iterdir

Resolves directory entries asynchronously as Path instances or native Dirents.

Signature:

iterdir(options?: {
extra?: {
withFileTypes?: false;
};
}): Promise<Path[]>;

Parameter

Type

Description

options

{ extra?: { withFileTypes?: false; }; }

(Optional) Optional flags controlling the return type.

Returns:

Promise<Path[]>

Promise resolving to directory entries as Path objects or Dirents.

The UnsupportedOperation When requesting withFileTypes on a runtime without support.

Pass extra.withFileTypes: true to receive Dirent objects. Throws UnsupportedOperation when the runtime does not support withFileTypes.

Loading directories asynchronously

import { Path } from "pathlib-ts";
const src = new Path("./src");
const entries = await src.iterdir();
console.log(entries.map((entry) => entry.name));