Skip to main content
Module

std/fs/expand_glob.ts>expandGlob

The Deno Standard Library
Latest
function expandGlob
import { expandGlob } from "https://deno.land/std@0.223.0/fs/expand_glob.ts";

Returns an async iterator that yields each file path matching the given glob pattern. The file paths are relative to the provided root directory. If root is not provided, the current working directory is used. The root directory is not included in the yielded file paths.

Requires the --allow-read flag.

Examples

Basic usage

File structure:

folder
├── script.ts
└── foo.ts
// script.ts
import { expandGlob } from "https://deno.land/std@0.223.0/fs/expand_glob.ts";

const entries = [];
for await (const entry of expandGlob("*.ts")) {
  entries.push(entry);
}

entries[0]!.path; // "/Users/user/folder/script.ts"
entries[0]!.name; // "script.ts"
entries[0]!.isFile; // false
entries[0]!.isDirectory; // true
entries[0]!.isSymlink; // false

entries[1]!.path; // "/Users/user/folder/foo.ts"
entries[1]!.name; // "foo.ts"
entries[1]!.isFile; // true
entries[1]!.isDirectory; // false
entries[1]!.isSymlink; // false

Parameters

glob: string | URL

The glob pattern to expand.

optional
unnamed 1: ExpandGlobOptions = [UNSUPPORTED]

Additional options for the expansion.

Returns

AsyncIterableIterator<WalkEntry>

An async iterator that yields each walk entry matching the glob pattern.