Skip to content

Path.glob() method

pathlib-ts > Path > glob

Globs files within this subtree asynchronously. Iterate over this subtree and yields all existing files (of any kind, including directories) matching the given relative pattern.

Signature:

glob(pattern: string, options?: fs.GlobOptions): Promise<Path[]>;

Parameter

Type

Description

pattern

string

Glob pattern interpreted relative to this path.

options

fs.GlobOptions

(Optional) Options forwarded to Node’s fs.glob implementation.

Returns:

Promise<Path[]>

Promise resolving to matching Path objects.

The UnsupportedOperation If globbing is not supported.

Matches CPython behaviour but relies on fs.glob. Throws UnsupportedOperation when the runtime lacks glob support. Options are forwarded to the underlying Node implementation.

Awaiting glob results for documentation

import { Path } from "pathlib-ts";
const docs = new Path("./docs");
const pages = await docs.glob("**.md");
console.log(pages.map((page) => page.name));