Skip to content

Instantly share code, notes, and snippets.

@clinyong
Created February 24, 2017 14:52
Show Gist options
  • Save clinyong/e6fb0a846d0dd624d021096a6371fe2e to your computer and use it in GitHub Desktop.
Save clinyong/e6fb0a846d0dd624d021096a6371fe2e to your computer and use it in GitHub Desktop.
walk directory
function walkDir(root) {
const stat = fs.statSync(root);
if (stat.isDirectory()) {
const dirs = fs.readdirSync(root).filter(item => !item.startsWith('.'));
let results = dirs.map(sub => walkDir(`${root}/${sub}`));
return [].concat(...results);
} else {
return root;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment