Skip to content

Instantly share code, notes, and snippets.

@azmenak
Created October 28, 2020 19:45
Show Gist options
  • Save azmenak/5c69d2a9b4d194a8fd3fbd6ba0dd7cb8 to your computer and use it in GitHub Desktop.
Save azmenak/5c69d2a9b4d194a8fd3fbd6ba0dd7cb8 to your computer and use it in GitHub Desktop.
import path from 'path'
import fs from 'fs'
function* getFilesRecursive(dir) {
const dirents = fs.readdirSync(dir, { withFileTypes: true });
for (const dirent of dirents) {
const res = path.resolve(dir, dirent.name);
if (dirent.isDirectory()) {
yield* getFiles(res);
} else {
yield res;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment