Skip to content

Path.walkSync() method

pathlib-ts > Path > walkSync

Traverse the directory tree synchronously and return the walk tuples.

Signature:

walkSync(options?: {
topDown?: boolean;
}): WalkTuple[];

Parameter

Type

Description

options

{ topDown?: boolean; }

(Optional) Control for traversal order (topDown).

Returns:

WalkTuple[]

An array of WalkTuple entries.

Mirrors Path.walk() but executes synchronously.

Summarising a tree synchronously

import { Path } from "pathlib-ts";
const root = new Path("./dist");
for (const [dir, dirs, files] of root.walkSync()) {
console.log(dir.toString(), dirs.length, files.length);
}