PYnative

Python Programming

  • Learn Python
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Exercises
    • Python Exercises
    • C Programming Exercises
    • C++ Exercises
  • Quizzes
  • Code Editor
    • Online Python Code Editor
    • Online C Compiler
    • Online C++ Compiler
Home » Python » Python Glob: Filename Pattern Matching

Python Glob: Filename Pattern Matching

Updated on: June 17, 2021 | 6 Comments

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.

FunctionDescription
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
Python glob module functions