Skip to content

Instantly share code, notes, and snippets.

@jeffmcmahan
Last active September 22, 2015 19:39
Show Gist options
  • Save jeffmcmahan/b026c1c9857f4fb30f64 to your computer and use it in GitHub Desktop.
Save jeffmcmahan/b026c1c9857f4fb30f64 to your computer and use it in GitHub Desktop.
Recursively, synchronously, read files from a directory with nodejs.
var recursiveReaddirSync = function (topDir) {
function readdir (dir) {
fs.readdirSync(dir).filter(function (pth) {
return !/^\./.test(pth)
}).forEach(function (pth) {
pth = path.join(dir, pth)
if (fs.lstatSync(pth).isDirectory()) readdir(pth)
else files.push(pth)
})
}
var files = []
readdir(topDir)
return files
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment