📜  fs.readdir 回调函数 - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:43.256000             🧑  作者: Mango

代码示例1
const Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs'));

var arr = [];

fs.readdirAsync(folder).then( files => {
  files.forEach(file => {
    fs.stat(folder + '/' + file, (err, stats) => {
       if(!stats.isDirectory()) {
         arr.push(file);
        return;
      }
     });
   });
})
.then( () => {
  console.log(arr);
});