Created
November 20, 2020 10:37
-
-
Save dmitriyzyuzin/26959794210cb478ff705ee6252fe93d to your computer and use it in GitHub Desktop.
Recursively walk through directory
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
async function walk(dir) { | |
let files = await fs.readdir(dir) | |
files = await Promise.all(files.map(async file => { | |
const filePath = path.join(dir, file) | |
const stats = await fs.stat(filePath) | |
if (stats.isDirectory()) { | |
return walk(filePath); | |
} | |
else if (stats.isFile()) { | |
return filePath; | |
} | |
})) | |
return files.reduce((all, folderContents) => all.concat(folderContents), []) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment