有谁知道是否可以使用 node-walk 模块通过扩展进行过滤? 我只想遍历以 *.log 结尾的文件 谢谢
最佳答案
我查看了源代码,它只公开了“过滤器”选项:
// Stop directories that contain filter keywords
// from continuing through the walk process
exclude = me._wfilters.some(function (filter) {
if (me._wcurpath.match(filter)) {
return true;
}
});
所以我使用 emitter.on 来过滤:
walker.on('file', function(root, stat, next) {
// Add this file to the list of files if it matches .log
if (stat.name.match('.log')) {
files.push(root + '/' + stat.name);
}
next();
});
walker.on('end', function() {
console.log(files);
});
性能明智不是最好的方法,但它可以完成工作。
关于javascript - nodejs - 使用 node-walk 过滤文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21141780/