Last active
February 9, 2023 04:12
-
-
Save JayMGurav/816e7c184d6cebcda3d51ae1f684d5eb to your computer and use it in GitHub Desktop.
Recursively traverse through the directory and list out all the files asynchronously
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
"use strict"; | |
const { readdir } = require("fs"); | |
const { promisify } = require("util"); | |
const readdirP = promisify(readdir); | |
async function getAllFilesRecursively(folder) { | |
return await ( | |
await readdirP(folder, { withFileTypes: true }) | |
).reduce(async (acc, curr) => { | |
if (curr.isDirectory()) { | |
return (await acc).concat( | |
await getAllCsvGzipFilesRecursively(`${folder}/${curr.name}`) | |
); | |
} else { | |
(await acc).push(`${folder}/${curr.name}`); | |
return acc; | |
} | |
}, Promise.resolve([])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment