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); });
|