path.ts 374 B

1234567891011121314
  1. import { join } from "path";
  2. import { readdir } from "fs/promises";
  3. // Walks a directory tree starting from path.
  4. export async function* walk(path: string): AsyncGenerator<string> {
  5. for (const entry of await readdir(path, { withFileTypes: true })) {
  6. if (entry.isDirectory()) {
  7. yield* walk(join(path, entry.name));
  8. } else {
  9. yield join(path, entry.name);
  10. }
  11. }
  12. }