Skip to content

Instantly share code, notes, and snippets.

View harupy's full-sized avatar
🇯🇵
Focusing

Harutaka Kawamura harupy

🇯🇵
Focusing
View GitHub Profile
@lovasoa
lovasoa / node-walk.es6
Last active June 20, 2024 08:38
Walk through a directory recursively in node.js.
// ES6 version using asynchronous iterators, compatible with node v10.0+
const fs = require("fs");
const path = require("path");
async function* walk(dir) {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory()) yield* walk(entry);
else if (d.isFile()) yield entry;