fs.glob(pattern[, options], callback)
pattern字符串|字符串数组options<Object>cwd<string> | <URL> 当前工作目录。默认值:process.cwd()exclude<Function> | <string[]> 用于过滤文件/目录的函数,或者要排除的全局匹配模式列表。如果提供的是函数,返回true表示排除该项,返回false表示包含该项。默认值:undefined。withFileTypes<boolean> 如果为true,则 glob 应返回路径作为 Dirent,否则为false。默认值:false。
callback<Function>err<Error>
- 检索与指定模式匹配的文件。
import { glob } from 'node:fs';
glob('**/*.js', (err, matches) => {
if (err) throw err;
console.log(matches);
});const { glob } = require('node:fs');
glob('**/*.js', (err, matches) => {
if (err) throw err;
console.log(matches);
});