You can download this code by clicking the button below.
This code is now available for download.
This function recursively searches for files that match the specified regular expression in the given root directory.
Technology Stack : os, re
Code Type : File search
Code Difficulty : Intermediate
import os
import re
import sys
import time
def find_files(root, pattern):
matches = []
for root, dirs, files in os.walk(root):
for filename in files:
if re.match(pattern, filename):
matches.append(os.path.join(root, filename))
return matches