Function dirList()
should return array of folders inside definded directory. I can't understand how return dirList
variable only after the function isDir()
is executed for each file.
I guess that I should use Q.all()
, but I don't know where I should put it :-(
var fs = require('fs'),
Q = require('q'),
readdir = Q.denodeify(fs.readdir);
function isDir(path) {
return Q.nfcall(fs.stat, __dirname + path)
.then(function (stats) {
if (stats.isDirectory()) {
return true;
} else {
return false;
}
});
}
function dirList(path) {
return readdir(__dirname + path).then(function (files) {
var dirList = files.filter(function (file) {
return isDir(path + file).then(function (isDir) {
return isDir;
});
});
return dirList;
});
}
dirList('/').done(
function (data) {
console.log(data);
},
function (err) {
console.log(err);
}
);