nodejs – 用节点行走过滤文件扩展名

有没有人知道是否有可能通过扩展与节点走模块过滤? 我只想走过以* .log结尾的文件谢谢

我看了一下源代码,它只公开了选项“filters”:

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

明智的performance并不是最好的方法,但它是做这个工作的。