# abc = res 操作的时候,res还没有结果
var abc;
Article.findArticle({}, function (err, res) {
if (err) {
console.log(err);
} else {
//操作查询出的文章
abc = res;
}
});
https://blog.csdn.net/qq_23870025/article/details/77920898
var dirList = [];
var fileList =[];
files.forEach(function(iterm){
var fullPath = path.join(wwwDir,iterm);
// 异步 这里异步处理会无法修改外部的list,data的结果滞后于代码执行【不知道这样理解对不对】
fs.stat(fullPath, function(err, data){
if (err) {
console.log(err);
} else {
if (data.isFile()){
fileList.push(iterm)
// console.log(‘file: ‘,fileList)
}else{
dirList.push(iterm)
}
}
});
// 同步
var stat = fs.lstatSync(fullPath);
console.log(fullPath,stat.mtime)
if (stat.isFile()){
fileList.push({‘fullPath‘:fullPath,‘fileSise‘:stat.size,‘mtime‘:stat.mtime});
}else{
console.log(fullPath)
dirList.push(fullPath);
}
});
console.log(‘dir: ‘,dirList)
console.log(‘file: ‘,fileList)
原文:https://www.cnblogs.com/amize/p/14869300.html