Function: findFilesRecursively()
findFilesRecursively(
path:PathLike,predicate: (filePath:string) =>boolean):AsyncIterableIterator<string>
Defined in: findFilesRecursively.ts:30
Parameters
| Parameter | Type | Description |
|---|---|---|
path | PathLike | The path in which to find files. |
predicate | (filePath: string) => boolean | A predicate function receives the path as a parameter. Truthy values will have the path included, falsey values will have the file excluded. |
Returns
AsyncIterableIterator<string>
An AsyncIterableIterator of all the files. To loop over these use for await (const file of findFilesRecursively(path, predicate)) {}
Examples
// With CommonJS: To find all files ending with `.ts` in the src directory:
const path = require('node:path');
for await (const file of findFilesRecursively(path.join(__dirname, 'src'), (filePath) => filePath.endsWith('.ts'))) {
console.log(file);
}
// With ESM: To find all files ending with `.ts` in the src directory:
for await (const file of findFilesRecursively(new URL('src', import.meta.url), (filePath) => filePath.endsWith('.ts'))) {
console.log(file);
}