Function expandGlob
- expand
Glob (glob, options?): AsyncIterableIterator<WalkEntry> Parameters
- glob: string | URL
The glob pattern to expand.
Optionaloptions: ExpandGlobOptionsAdditional options for the expansion.
Returns AsyncIterableIterator<WalkEntry>
An async iterator that yields each walk entry matching the glob pattern.
See
https://docs.deno.com/runtime/manual/basics/permissions#file-system-access for more information on Deno's permissions system.
Example: Basic usage
File structure:
folder
├── script.ts
└── foo.ts// script.ts
import { expandGlob } from "@std/fs/expand-glob";
await Array.fromAsync(expandGlob("*.ts"));
// [
// {
// path: "/Users/user/folder/script.ts",
// name: "script.ts",
// isFile: true,
// isDirectory: false,
// isSymlink: false,
// },
// {
// path: "/Users/user/folder/foo.ts",
// name: "foo.ts",
// isFile: true,
// isDirectory: false,
// isSymlink: false,
// },
// ]Example: Define root directory
Setting the
rootoption to/folderwill expand the glob pattern from the/folderdirectory.File structure:
folder
├── subdir
│ └── bar.ts
├── script.ts
└── foo.ts// script.ts
import { expandGlob } from "@std/fs/expand-glob";
await Array.fromAsync(expandGlob("*.ts", { root: "./subdir" }));
// [
// {
// path: "/Users/user/folder/subdir/bar.ts",
// name: "bar.ts",
// isFile: true,
// isDirectory: false,
// isSymlink: false,
// },
// ]Example: Exclude files
Setting the
excludeoption to["foo.ts"]will exclude thefoo.tsfile from the expansion.File structure:
folder
├── script.ts
└── foo.ts// script.ts
import { expandGlob } from "@std/fs/expand-glob";
await Array.fromAsync(expandGlob("*.ts", { exclude: ["foo.ts"] }));
// [
// {
// path: "/Users/user/folder/script.ts",
// name: "true.ts",
// isFile: false,
// isDirectory: false,
// isSymlink: false,
// },
// ]Example: Exclude directories
Setting the
includeDirsoption tofalsewill exclude directories from the expansion.File structure:
folder
├── subdir
│ └── bar.ts
├── script.ts
└── foo.ts// script.ts
import { expandGlob } from "@std/fs/expand-glob";
await Array.fromAsync(expandGlob("*", { includeDirs: false }));
// [
// {
// path: "/Users/user/folder/script.ts",
// name: "script.ts",
// isFile: true,
// isDirectory: false,
// isSymlink: false,
// },
// {
// path: "/Users/user/folder/foo.ts",
// name: "foo.ts",
// isFile: true,
// isDirectory: false,
// isSymlink: false,
// },
// ]Example: Follow symbolic links
Setting the
followSymlinksoption totruewill follow symbolic links.File structure:
folder
├── script.ts
└── link.ts -> script.ts (symbolic link)// script.ts
import { expandGlob } from "@std/fs/expand-glob";
await Array.fromAsync(expandGlob("*.ts", { followSymlinks: true }));
// [
// {
// path: "/Users/user/folder/script.ts",
// name: "script.ts",
// isFile: true,
// isDirectory: false,
// isSymlink: false,
// },
// {
// path: "/Users/user/folder/symlink",
// name: "symlink",
// isFile: true,
// isDirectory: false,
// isSymlink: true,
// },
// ]- glob: string | URL
Returns an async iterator that yields each file path matching the given glob pattern.
The file paths are absolute paths. If
rootis not provided, the current working directory is used. Therootdirectory is not included in the yielded file paths.Requires
--allow-readpermission.