Skip to content

Path.walk() method

pathlib-ts > Path > walk

Walk the directory tree from this directory.

Signature:

walk(options?: {
topDown?: boolean;
}): Promise<WalkTuple[]>;

Parameter

Type

Description

options

{ topDown?: boolean; }

(Optional) Control for traversal order (topDown).

Returns:

Promise<WalkTuple[]>

Promise resolving to an array of WalkTuple entries.

Returns WalkTuple entries while delegating to the synchronous walker via Promise wrapper.

Copying a tree using walk

import { Path } from "pathlib-ts";
const source = new Path("./build");
const target = new Path("./public");
for (const [dir, , files] of await source.walk()) {
const rel = dir.relativeTo(source, { walkUp: true });
const outDir = target.joinpath(rel) as Path;
await outDir.mkdir({ parents: true, existOk: true });
for (const name of files) {
await dir.joinpath(name).copy(outDir.joinpath(name));
}
}