Skip to content

Instantly share code, notes, and snippets.

@tomchentw
Created February 12, 2015 21:13
Show Gist options
  • Save tomchentw/9328ede9aa373cf8b6d6 to your computer and use it in GitHub Desktop.
Save tomchentw/9328ede9aa373cf8b6d6 to your computer and use it in GitHub Desktop.
listing directory
/*
* This is a synchronized vesion. Please rewrite in async version using Promise.
* Note: You may directly use https://github.com/normalize/mz
*
*/
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