Skip to content

Instantly share code, notes, and snippets.

@ifiokjr
Created October 27, 2018 07:40
Show Gist options
  • Save ifiokjr/3e83028ffe52e77e33d73dc1b2b2cb65 to your computer and use it in GitHub Desktop.
Save ifiokjr/3e83028ffe52e77e33d73dc1b2b2cb65 to your computer and use it in GitHub Desktop.
Get all directories with nodejs 10+ fs.promises
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