今天需要获取到一个目录,包含子目录里的文件里的所有文件名, 而fs module里只有单层的文件,自己写要递归,不过有现成的node-walk模块,就直接可以用了。

npm install walk

装完了就可以用了。

var walk    = require('walk');
var files = [];

// Walker options
var walker = walk.walk('./test', { followLinks: false });

walker.on('file', function(root, stat, next) {
// Add this file to the list of files
files.push(root + '/' + stat.name);
next();
});

walker.on('end', function() {
console.log(files);
});

API和详细事例见https://github.com/coolaj86/node-walk

相关文章:

  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2021-06-03
  • 2022-01-23
  • 2022-02-20
  • 2022-02-07
  • 2021-10-12
猜你喜欢
  • 2021-12-26
  • 2021-09-04
  • 2020-12-24
  • 2021-11-15
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案