Created
October 27, 2018 07:40
-
-
Save ifiokjr/3e83028ffe52e77e33d73dc1b2b2cb65 to your computer and use it in GitHub Desktop.
Get all directories with nodejs 10+ fs.promises
This file contains hidden or 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 { lstat, readdir } = require('fs').promises; | |
const pFilter = require('p-filter'); // Promise filter although this can easily be replaced. | |
const isDirectory = async source => { | |
const stats = await lstat(source); | |
return stats.isDirectory(); | |
}; | |
const getDirectories = async source => { | |
const list = await readdir(source); | |
const resolvedList = list.map(name => join(source, name)); | |
return pFilter(resolvedList, isDirectory); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment