Skip to content

Instantly share code, notes, and snippets.

@un33k
Forked from kethinov/walksync.js
Created March 7, 2018 22:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save un33k/2d158b5c04abfc2991a7834f37231b0f to your computer and use it in GitHub Desktop.
Save un33k/2d158b5c04abfc2991a7834f37231b0f to your computer and use it in GitHub Desktop.
List all files in a directory in Node.js recursively in a synchronous fashion
// List all files in a directory in Node.js recursively in a synchronous fashion
var walkSync = function(dir, filelist) {
var fs = fs || require('fs'),
files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function(file) {
if (fs.statSync(dir + file).isDirectory()) {
filelist = walkSync(dir + 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