Created
June 29, 2018 01:04
-
-
Save dmtrmrv/0c96839f693eb93aff413ae418df51e7 to your computer and use it in GitHub Desktop.
Recursively return folders in Node.js
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
const getFolders = (dir) => { | |
const paths = [dir]; | |
const scan = (dir) => { | |
fs.readdirSync(dir).forEach((item) => { | |
if (fs.statSync(path.join(dir, item)).isDirectory()) { | |
const subdir = `${dir + item}/`; | |
paths.push(subdir); | |
scan(subdir); | |
} | |
}); | |
}; | |
scan(dir); | |
return paths; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment