Skip to content

Instantly share code, notes, and snippets.

@arayaryoma
Created May 7, 2019 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arayaryoma/ec4a69c0b41b6619da50ee23812f658d to your computer and use it in GitHub Desktop.
Save arayaryoma/ec4a69c0b41b6619da50ee23812f658d to your computer and use it in GitHub Desktop.
const readdirRecursively = async (dir, files = []) => {
const dirents = await fsPromises.readdir(dir, {withFileTypes: true});
const dirs = [];
for (let dirent of dirents) {
if (dirent.isDirectory()) dirs.push(`${dir}/${dirent.name}`);
if (dirent.isFile()) files.push(`${dir}/${dirent.name}`);
}
for (let d of dirs) {
files = readdirRecursively(d, files)
}
return Promise.resolve(files);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment