Created
May 7, 2019 04:57
-
-
Save arayaryoma/ec4a69c0b41b6619da50ee23812f658d to your computer and use it in GitHub Desktop.
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 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