.glob()

BrandonDusch580 total contributions
Published Jun 25, 2022
Contribute to Docs
The .glob()
method returns a list of possible matches for a pathname string.
Syntax
glob.glob(pathname, recursive)
The pathname
must be a valid string that represents a file path that can either be absolute or relative.
By default, recursive
is set to False
. But when set to True
, the pattern **
can be used to match any files and folders in a given directory.
Example
The example below showcases some common use-cases for the .glob()
method:
import glob# Files in current folderglob.glob('*.*')# Files in subfolderglob.glob('*/*')# Everything in current folderglob.glob('**/*', recursive=True)
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.