如下有个遍历文件夹的函数,如何才能得知它已经遍历结束了? 谢谢!
function walk(path, floor, handleFile) {
// handleFile(path, floor);
floor++;
fs.readdir(path, function(err, files) {
if (err) {
console.log('read dir error');
} else {
files.forEach(function(item) {
var tmpPath =path + '/' + item;
fs.stat(tmpPath, function(err1, stats,people,factor) {
if (err1) {
console.log('stat error');
} else {
if (stats.isDirectory()) {
walk(tmpPath, floor, handleFile);
} else {
handleFile(tmpPath,item, floor);
}
}
})
});
}
});
}