tf.io.gfile.glob
Stay organized with collections
Save and categorize content based on your preferences.
Returns a list of files that match the given pattern(s).
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
for implementation details.
Args |
pattern
|
string or iterable of strings. The glob pattern(s).
|
Returns |
A list of strings containing filenames that match the given pattern(s).
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-03-17 UTC.
[null,null,["Last updated 2023-03-17 UTC."],[],[],null,["# tf.io.gfile.glob\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.9.3/tensorflow/python/lib/io/file_io.py#L383-L449) |\n\nReturns a list of files that match the given pattern(s).\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.io.gfile.glob`](https://www.tensorflow.org/api_docs/python/tf/io/gfile/glob)\n\n\u003cbr /\u003e\n\n tf.io.gfile.glob(\n pattern\n )\n\nThe patterns are defined as strings. Supported patterns are defined\nhere. Note that the pattern can be a Python iteratable of string patterns.\n\nThe format definition of the pattern is:\n\n**pattern** : `{ term }`\n\n**term**:\n\n- `'*'`: matches any sequence of non-'/' characters\n- `'?'`: matches a single non-'/' character\n- `'[' [ '^' ] { match-list } ']'`: matches any single character (not) on the list\n- `c`: matches character `c` where `c != '*', '?', '\\\\', '['`\n- `'\\\\' c`: matches character `c`\n\n**character range**:\n\n- `c`: matches character `c` while `c != '\\\\', '-', ']'`\n- `'\\\\' c`: matches character `c`\n- `lo '-' hi`: matches character `c` for `lo \u003c= c \u003c= hi`\n\n#### Examples:\n\n tf.io.gfile.glob(\"*.py\")\n # For example, ['__init__.py']\n\n tf.io.gfile.glob(\"__init__.??\")\n # As above\n\n files = {\"*.py\"}\n the_iterator = iter(files)\n tf.io.gfile.glob(the_iterator)\n # As above\n\nSee the C++ function `GetMatchingPaths` in\n[`core/platform/file_system.h`](../../../core/platform/file_system.h)\nfor implementation details.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------|-----------------------------------------------------|\n| `pattern` | string or iterable of strings. The glob pattern(s). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A list of strings containing filenames that match the given pattern(s). ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|----------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|\n| [`errors.OpError`](https://www.tensorflow.org/api_docs/python/tf/errors/OpError) | If there are filesystem / directory listing errors. |\n| [`errors.NotFoundError`](https://www.tensorflow.org/tfx/ml_metadata/api_docs/python/mlmd/errors/NotFoundError) | If pattern to be matched is an invalid directory. |\n\n\u003cbr /\u003e"]]