Skip to content

Instantly share code, notes, and snippets.

@feload
Forked from dlabey/readdir_recurs_sync.js
Created November 23, 2017 20:41
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 feload/0b89899094799c8847ac4fb468086529 to your computer and use it in GitHub Desktop.
Save feload/0b89899094799c8847ac4fb468086529 to your computer and use it in GitHub Desktop.
NodeJS ReaddirSync Recursive
function readdirRecursSync(dir, filelist) {
filelist = filelist || [];
var files = fs.readdirSync(dir);
files.forEach(function (file) {
file = path.join(dir, file);
if (fs.statSync(file).isDirectory()) {
filelist = readdirRecursSync(file, filelist);
} else {
filelist.push(file);
}
});
return filelist;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment