fs.glob(pattern[, options], callback)
¥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, returntrue
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
.
-
-
callback
<Function>err
<Error>
-
检索与指定模式匹配的文件。
¥Retrieves the files matching the specified pattern.
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);
});