I am trying to generate a directory tree into an array using node js. Output would be:
[ __Dirname [array of sub directories] ]
["FolderA"[ ["SubFolderA",[]] ]], ["FolderB",[]]
function readDir(dir){
fs.readdir(dir, function(err, files){
for(var i=0;i<files.length;i++){
(function(j){
fs.stat(files[j], function(err, stats){
if(stats.isDirectory()){
readDir(files[j]);
}
});
}
}
});
}
If you know an easier way to do this please inform me. All I need is a list of directories and all their sub directories recursively.