fsPromises.glob(pattern[, options])
¥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
.
-
-
返回:<AsyncIterator> 一个 AsyncIterator,它生成与模式匹配的文件的路径。
¥Returns: <AsyncIterator> An AsyncIterator that yields the paths of files that match the pattern.
import { glob } from 'node:fs/promises';
for await (const entry of glob('**/*.js'))
console.log(entry);
const { glob } = require('node:fs/promises');
(async () => {
for await (const entry of glob('**/*.js'))
console.log(entry);
})();