To use Glob () to find files recursively, you need Python 3.5+. The glob module supports the "**" directive (which is only parsed if you pass a recursive flag) that tells Python to recursively search directories.
import glob for filename in glob.iglob (’src / ** / *’, recursive = True): print ( filename)
You can check the filename using any condition using an if statement. For older versions of Python, you can use os.walk to traverse a directory recursively and find files.
import os, re, os.path pattern = "^ your_regex_here $" mypath = "my_folder" for root, dirs, files in os.walk (mypath): for file in filter (lambda x: re.match (pattern, x), files): print (file)
This will match the filename with the regex you specified and print their names.