分站内容可能或出现渲染错误或内容过时等问题,请以主站为准!
分站禁止评论,评论请前往主站!
代码如下:
const path = require("path"); const fs = require("fs");
const pathName = "./"; fs.readdir(pathName, function(err, files){ let fileArr = []; let dirArr = []; let otherArr = []; (function iterator(i){ if(i == files.length) { console.log({"files":fileArr,"dirs":dirArr,"others":otherArr}); return ; } fs.stat(path.join(pathName, files[i]), function(err, data){ if(data.isFile()){ fileArr.push(path.extname(files[i])); }else if(data.isDirectory()){ dirArr.push(files[i]); }else{ otherArr.push(files[i]); } iterator(i+1); }); })(0); });
|