Skip to content

Instantly share code, notes, and snippets.

@dmitriyzyuzin
Created November 20, 2020 10:37
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 dmitriyzyuzin/26959794210cb478ff705ee6252fe93d to your computer and use it in GitHub Desktop.
Save dmitriyzyuzin/26959794210cb478ff705ee6252fe93d to your computer and use it in GitHub Desktop.
Recursively walk through directory
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