Skip to content

Instantly share code, notes, and snippets.

@Ivannnnn
Created September 25, 2022 16:29
Show Gist options
  • Save Ivannnnn/d1c88bc319caec8f70647467d82b1f47 to your computer and use it in GitHub Desktop.
Save Ivannnnn/d1c88bc319caec8f70647467d82b1f47 to your computer and use it in GitHub Desktop.
const path = require("path");
function* walkSync(dir) {
const files = fs.readdirSync(dir, { withFileTypes: true });
for (const file of files) {
file.isDirectory()
? yield* walkSync(path.join(dir, file.name))
: yield path.join(dir, file.name);
}
}
const readDirRecursive = (dir) => [...walkSync(dir)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment