find files by extension, *.html under a folder in nodejs

后端 未结 14 698
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 23:57

I\'d like to find all *.html files in src folder and all its sub folders using nodejs. What is the best way to do it?

var folder = \'/project1/src\';
var ex         


        
14条回答
  •  时光说笑
    2020-12-08 00:42

    What, hang on?! ... Okay ya, maybe this makes more sense to someones else too.

    [nodejs 7 mind you]

    fs = import('fs');
    let dirCont = fs.readdirSync( dir );
    let files = dirCont.filter( function( elm ) {return elm.match(/.*\.(htm?html)/ig);});
    

    Do whatever with regex make it an argument you set in the function with a default etc.

提交回复
热议问题