walkPaths
walkPaths(
options?):AsyncGenerator<WalkedPath>
Defined in: packages/node/src/fs/walk-paths.ts:308
Streams the paths under a directory, filtered by globs, regular expressions or predicates.
Paths are yielded relative to the root, /-separated on every platform, and
sorted within each directory. Because one traversal tests every filter, a
path is yielded once no matter how many patterns it matches — no
deduplication needed. Stop early by breaking out of the loop; the generator’s
cleanup runs as usual.
Depth comes from the patterns, as it does in a shell: "*.ts" stays flat,
"**/*.ts" recurses. WalkPathsOptions.descend overrides that, and
is the only way to recurse with a regular expression or a predicate.
Time complexity: one readdir per directory descended into, and one filter
test per entry visited. exclude is applied before descending, so an
excluded subtree is never read.
Parameters
Section titled “Parameters”options?
Section titled “options?”Root, filters, depth, symlink and error handling. See WalkPathsOptions.
Returns
Section titled “Returns”AsyncGenerator<WalkedPath>
The matching paths, each with the directory entry it came from.
Examples
Section titled “Examples”Every .bench.ts outside node_modules
ts for await (const { path } of walkPaths({ include: "**/*.bench.ts", exclude: "**/node_modules/**", })) { console.log(path); }
The CPU directories of sysfs, tolerating an absent tree
ts const names = await Array.fromAsync( walkPaths({ root: "/sys/devices/system/cpu", include: /^cpu\d+$/, unreadable: "skip", }), (walked) => walked.path, );
Throws
Section titled “Throws”When a directory cannot be read and WalkPathsOptions.unreadable does not tolerate it.