---
name: "glob"
section: "3bobcat"
platform: "linux"
package: "libbobcat-dev"
version: "6.07.01-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/glob/3bobcat"
---

# glob(3bobcat)

Wrapper around glob(3) to find files matching a pattern

## NAME

FBB::Glob - Wrapper around [**glob**(3)](/glob/3.md) to find files matching a pattern

## SYNOPSIS

**#include \<bobcat/glob\>**\
 Linking option: *-lbobcat*

## DESCRIPTION

The **FBB::Glob** class is a wrapper around the **C** function [**glob**(3)](/glob/3.md). It returns a list of files matching a certain pattern provided to **FBB::Glob**’s constructors or members.

## NAMESPACE

**FBB**\
 All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace **FBB**.

## INHERITS FROM

\-

## ENUMERATIONS

**Glob::Type**: \
 This enumeration, which is identical to the [**stat**(3bobcat)](/stat/3bobcat.md) *Type* enumeration, defines the following values:

- o

  **BLOCK\_DEVICE** (0060000): the object is a block device;

- o

  **CHARACTER\_DEVICE** (0020000): the object is a character device;

- o

  **DIRECTORY** (0040000): the object is a directory;

- o

  **FIFO** (0010000): the object is a named pipe (a queue);

- o

  **REGULAR\_FILE** (0100000): the object is a regular file;

- o

  **SOCKET** (0140000): the object is a socket;

- o

  **SYMBOLIC\_LINK** (0120000): the object is a symbolic link;

- o

  **ANY**: any of the above types.

These values are also used by [**stat**(2)](/stat/2.md) and [**lstat**(2)](/lstat/2.md). Although they can be combined using the *bitor* operator, they are not uniquely recognizable when combined. E.g., the value of *CHARACTER\_DEVICE \|* *DIRECTORY* is equal to the value of *BLOCK\_DEVICE*. It’s also possible to combine *Type* values in a *std::unordered\_set*, which avoids the confusion that may result from using the *bitor* operator.

**Glob::Flags**:

- o

  *NO\_FLAG*:   Equals 0, and can be used to avoid having to specify 0. It has no further use.

- o

  *ERR*: Return on read errors;

- o

  *MARK*: Append a slash to each name.

- o

  *NOSORT*: Don’t sort the names.

- o

  *NOESCAPE*: Backslashes don’t quote metacharacters.

- o

  *PERIOD*: Leading *.*-characters can be matched by metachars (i.e., *\** and *?*).

- o

  *NOMATCH*: When specified the constructors won’t throw exceptions when no files matching their glob-patterns could be found. Instead they will return normally, and *Glob’s size()* member (see below) will return 0.

**Glob::Dots**:

- o

  *FIRST*: Filenames starting with a dot will be listed first. Within this set and in the leftover-set the relative ordering is maintained.

- o

  *DEFAULT*: Return filenames as they appear in the globbing process.

## CONSTRUCTORS

- o

  **Glob(std::string const &pattern = "\*", int flags = PERIOD,** **Dots dots = FIRST)**:\
   This constructor (which can also be used as the default constructor) determines all elements matching *pattern*.

-

  An *Exception* exception is thrown if the constructor could not properly complete it tasks.

-

  Multiple flags may be specified, separated by the *bitor* operator.

-

  This constructor properly completes its task if only defined **Flag** values were specified and if the [**glob**(3)](/glob/3.md) function returned without errors;

-

  - o

  **Glob(Type type, std::string const &pattern = "\*", int flags = PERIOD,** **Dots dots = FIRST)**:\
   This constructor determines all elements of *pattern* when their types \`*elementType*’ are equal to the value of *elementType &* *type*. The specified *type* value may consist of any *bitor*-ed combination of enum values defined by the *Type* enum. Note that this may produce confusing results. E.g., when specifying *DIRECTORY*, elements that are *BLOCK\_DEVICEs* or *SOCKETs* are also accepted. The next constructor can be used to avoid this confusion;

-

  - o

  **Glob(std::unordered\_set\<Type\> const &typeSet,** **std::string const &pattern = "\*", int flags = PERIOD,** **Dots dots = FIRST)**:\
   This constructor determines all elements of *pattern* when their types are found in *typeSet*. Different from the previous constructor, for an element to be accepted its type must exactly match a type value in the *typeSet* set.

Copy and move constructors (and assignment operators) are available.

## OVERLOADED OPERATORS

- o

  **char const \*operator\[\](size\_t idx) const**:\
   The element at index position *idx* is returns as a **C** string. It returns an empty string if *idx* is or exceeds **size()**.

## MEMBER FUNCTIONS

- o

  **size\_t size() const**:\
   Returns the number of elements that were detected;

- o

  **char const \*const \*begin() const**:\
   Returns a pointer to the first element that was detected. This pointer can be used in generic algorithms as an output-iterator supporting pointer arithmetic;

- o

  **char const \*const \*end() const**:\
   Returns a pointer beyond the last element that was detected. This pointer can be used in generic algorithms as an output-iterator supporting pointer arithmetic;

- o

  **void swap(Glob &other)**:\
   Swaps the content of the other object with the current object.

## EXAMPLES

```
    int main(int argc, char **argv)
    {
        if (argc == 1)
        {
            cout << "Provide glob-expression as 1st arg\n";
            return 1;
        }
        cout << "General:\n";
        Glob general;
        for (size_t idx = 0; idx < general.size(); idx++)
            cout << idx << ": " << general[idx] << endl;
        cout << "Pattern: " << argv[1] << "\n";
        Glob pattern(argv[1], Glob::PERIOD, Glob::DEFAULT);
        for (size_t idx = 0; idx < pattern.size(); idx++)
            cout << idx << ": " << pattern[idx] << endl;
    }
```

## FILES

*bobcat/glob* - defines the class interface

## SEE ALSO

[**bobcat**(7)](/bobcat/7.md), [**stat**(3bobcat)](/stat/3bobcat.md), [**glob**(3)](/glob/3.md)

## BUGS

No Reported Bugs.

## BOBCAT PROJECT FILES

- o

  *https://fbb-git.gitlab.io/bobcat/*: gitlab project page;

Debian Bobcat project files:

- o

  *libbobcat6*: debian package containing the shared library, changelog and copyright note;

- o

  *libbobcat-dev*: debian package containing the static library, headers, manual pages, and developer info;

## BOBCAT

Bobcat is an acronym of \`Brokken’s Own Base Classes And Templates’.

## COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

## AUTHOR

Frank B. Brokken (**f.b.brokken@rug.nl**).
