Created
February 24, 2017 14:52
-
-
Save clinyong/e6fb0a846d0dd624d021096a6371fe2e to your computer and use it in GitHub Desktop.
walk directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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