Path.glob

Path[] glob(string pattern) const

Globs for filesystem entries under this directory that match the given pattern.

This implements pathlib-like semantics with support for recursive "**" segments, dotfile rules, and platform case sensitivity.

Semantics overview:

  • The pattern is interpreted as relative to this path (which is treated as

the search root). Absolute patterns (with a root/drive/UNC) are rejected.

  • Wildcards within a single path segment are supported: `*`, `?`, and character

classes like [abc] and [!abc].

  • The special segment with two asterisks ("double star") matches zero or more

complete path segments (recursive). As a trailing segment (for example, a pattern ending with double-star), it matches all descendants of the preceding directory.

  • Dotfile rule: wildcard segments do NOT match names starting with `.` unless the

segment itself begins with `.`. Literal segments behave as exact comparisons. For a double-star segment, descending into hidden dot-directories is allowed only if the next pattern segment begins with a dot. Example: a pattern where the next component starts with '.' (like ".name/file" or ".[set]/file").

  • Case sensitivity: POSIX comparisons are case-sensitive; Windows comparisons are

case-insensitive (matching Python's pathlib behavior).

  • Errors while listing a directory (e.g., permissions) are ignored and the subtree

is skipped. This mirrors common globbing behavior for robustness.

Returns absolute paths when this is absolute; otherwise returns paths relative to this by joining matched names. Both files and directories can be returned when they match the final segment.

Parameters

patternRelative glob pattern to match under this path. Must not be empty.

Examples

// Find text files at the root (hidden files are excluded by default)
auto txt = Path("/logs").glob("*.txt");
// Recursive search with a double-star segment
auto anyTxt = Path("/logs").glob("**" ~ "/" ~ "*.txt");
// Hidden entries: the segment must start with a dot
auto hidden = Path("/cfg").glob(".*");

Returns

An array of matching paths.

Throws

Exception if the pattern is empty or absolute.