node.js fs.readdir recursive directory search

前端 未结 30 2020
醉酒成梦
醉酒成梦 2020-11-22 15:55

Any ideas on an async directory search using fs.readdir? I realise that we could introduce recursion and call the read directory function with the next directory to read, bu

30条回答
  •  无人共我
    2020-11-22 16:32

    Use node-dir to produce exactly the output you like

    var dir = require('node-dir');
    
    dir.files(__dirname, function(err, files) {
      if (err) throw err;
      console.log(files);
      //we have an array of files now, so now we can iterate that array
      files.forEach(function(path) {
        action(null, path);
      })
    });
    

提交回复
热议问题