fs.globSync(pattern[, options])


稳定性: 1 - 实验性的

¥Stability: 1 - Experimental

  • pattern <string> | <string[]>

  • options <Object>

    • cwd <string> 当前工作目录。默认值:process.cwd()

      ¥cwd <string> current working directory. Default: process.cwd()

    • exclude <Function> | <string[]> 用于过滤文件/目录或要排除的 glob 模式列表的函数。如果提供了函数,则返回 true 以排除该项目,返回 false 以包含它。默认值:undefined

      ¥exclude <Function> | <string[]> Function to filter out files/directories or a list of glob patterns to be excluded. If a function is provided, return true to exclude the item, false to include it. Default: undefined.

    • withFileTypes <boolean> 如果 glob 应将路径返回为 Dirents,则为 true,否则为 false。默认值:false

      ¥withFileTypes <boolean> true if the glob should return paths as Dirents, false otherwise. Default: false.

  • 返回:与模式匹配的文件的 <string[]> 路径。

    ¥Returns: <string[]> paths of files that match the pattern.

import { globSync } from 'node:fs';

console.log(globSync('**/*.js'));const { globSync } = require('node:fs');

console.log(globSync('**/*.js'));