# tf.io.gfile.glob

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/lib/io/file_io.py#L385-L451) |

Returns a list of files that match the given pattern(s).

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.io.gfile.glob`](https://www.tensorflow.org/api_docs/python/tf/io/gfile/glob)

<br />

    tf.io.gfile.glob(
        pattern
    )

The patterns are defined as strings. Supported patterns are defined
here. Note that the pattern can be a Python iteratable of string patterns.

The format definition of the pattern is:

**pattern** : `{ term }`

**term**:

- `'*'`: matches any sequence of non-'/' characters
- `'?'`: matches a single non-'/' character
- `'[' [ '^' ] { match-list } ']'`: matches any single character (not) on the list
- `c`: matches character `c` where `c != '*', '?', '\\', '['`
- `'\\' c`: matches character `c`

**character range**:

- `c`: matches character `c` while `c != '\\', '-', ']'`
- `'\\' c`: matches character `c`
- `lo '-' hi`: matches character `c` for `lo <= c <= hi`

#### Examples:

    tf.io.gfile.glob("*.py")
    # For example, ['__init__.py']

    tf.io.gfile.glob("__init__.??")
    # As above

    files = {"*.py"}
    the_iterator = iter(files)
    tf.io.gfile.glob(the_iterator)
    # As above

See the C++ function `GetMatchingPaths` in
[`core/platform/file_system.h`](https://www.tensorflow.org/versions/r2.13/api_docs/python/core/platform/file_system.h)
for implementation details.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `pattern` | string or iterable of strings. The glob pattern(s). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A list of strings containing filenames that match the given pattern(s). ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| [`errors.OpError`](https://www.tensorflow.org/api_docs/python/tf/errors/OpError) | If there are filesystem / directory listing errors. |
| [`errors.NotFoundError`](https://www.tensorflow.org/tfx/ml_metadata/api_docs/python/mlmd/errors/NotFoundError) | If pattern to be matched is an invalid directory. |

<br />