如何使用 Node.js 在 a 中使用通配符从目录中读取文件

Nod*_*ewb 3 file wildcard

我需要使用 Node.js 从目录中读取文件,文件名都是 .json 如何在 Node.js 中对文件名部分使用通配符?

pra*_*sun 5

您可以使用globnpm来使用通配符文件名模式匹配

var glob = require("glob")

// options is optional
glob("DIR_PATH/*.json", options, function (er, files) {
  // files is an array of filenames.
  // er is an error object or null.
})
Run Code Online (Sandbox Code Playgroud)