preliminary learning Node, keeps reporting Cannot read property "isDirectory" of undefined, when doing a read about files, judging whether the type of each file is a file directory, and then I try to use isFile, to also report undefined
related codes
function file(i) {
var filename = filesarry[i];
fs.stat(__dirname + "/" + filesarry[i], function(err, stat) {
stats[i] = stat;
if (stat.isDirectory()) {
console.log(" " + i + " \033[36m" + filesarry[i] + "/\033[39m");
} else {
console.log(" " + i + " \033[90m" + filename + "/\033[39m");
}
iPP;
if (i == filesarry.length) {
read();
} else {
file(i);
}
});
}
:
C:\Users\DZY\Desktop\Node\\file-explorer\index.js:28
if (stat.isDirectory()) {
^
TypeError: Cannot read property "isDirectory" of undefined
at C:\Users\DZY\Desktop\Node\\file-explorer\index.js:28:14
at FSReqWrap.oncomplete (fs.js:152:21)