The glob module, part of the Python Standard Library, is used to find the files and folders whose names follow a specific pattern. The searching rules are similar to the Unix Shell path expansion rules.
After reading this article, you will learn:
- How to find all files that match the specified pattern
- How to search files recursively using the
glob()function - The
iglob()to iterate over a list of filenames. - Search Files Using Wildcard Characters
The following are the list of functions available in the glob module. we’ll learn each one by one.
| Function | Description |
|---|---|
glob.glob(pathname) | Returns a list of files that matches the path specified in the function argument |
glob.iglob(pathname) | Return a generator object that we can iterate over and get the individual file names |
glob.escape(pathname) | Useful especially in the case of the filenames with special characters |