Path.walk() method
pathlib-ts > Path > walk
Path.walk() method
Section titled “Path.walk() method”Walk the directory tree from this directory.
Signature:
walk(options?: { topDown?: boolean; }): Promise<WalkTuple[]>;Parameters
Section titled “Parameters”|
Parameter |
Type |
Description |
|---|---|---|
|
options |
{ topDown?: boolean; } |
(Optional) Control for traversal order ( |
Returns:
Promise<WalkTuple[]>
Promise resolving to an array of WalkTuple entries.
Remarks
Section titled “Remarks”Returns WalkTuple entries while delegating to the synchronous walker via Promise wrapper.
Example
Section titled “Example”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)); }}