blob: 3e9394201ff71598bd5ff5620f0b39ec36bc19c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import { readdir } from 'node:fs/promises';
import { resolve } from 'node:path';
/**
* recursively get all files in a directory
* @param {string} directory the directory to read
* @yields {string} the path to each file
* @return {AsyncGenerator<string>} the path to each file
*/
export async function* getFiles(directory) {
for (const entry of await readdir(directory, { withFileTypes: true })) {
const path = resolve(directory, entry.name);
if (entry.isDirectory()) {
yield* getFiles(path);
} else {
yield path;
}
}
}
|