How do I get a list of files with specific file extension using node.js?

后端 未结 4 1372
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 00:37

The node fs package has the following methods to list a directory:

fs.readdir(path, [callback]) Asynchronous readdir(3). Reads the

4条回答
  •  遥遥无期
    2020-12-31 01:36

    fs doesn't support filtering itself but if you don't want to filter youself then use glob

    var glob = require('glob');
    
    // options is optional
    glob("**/*.js", options, function (er, files) {
      // files is an array of filenames.
      // If the `nonull` option is set, and nothing
      // was found, then files is ["**/*.js"]
      // er is an error object or null.
    })
    

提交回复
热议问题