Question: implement a recursive function with signature find ( path , filename ) that reports all entries of the file system rooted at the given path

implement a recursive function with signature find(path, filename) that reports all entries of the file system rooted at the given path (relative path i.e. from wherever the program is located) having the given file name (partial match).
Use the base code given below and write the program in Python:
import os
# Assignment: Programming Project 2, P-4.23
def find(path, filename):
"""
This function searches for a specific filename in a given path using recursion.
Parameters:
path (str): The root path from which the search should begin.
filename (str): The filename to search for. A partial match is sufficient.
Returns:
None. The function should print the full path of each matching file.
"""
# WRITE YOUR CODE HERE
# Hint: You can use os.listdir(path) to get a list of all files and directories in 'path'.
# For each entry in this list, use os.path.join(path, entry) to get the full path.
# Check if this path ends with 'filename'. If it does, print the path.
# If the entry is a directory, call the 'find' function recursively with the new path.
if __name__=='__main__':
path ="./TDir/" # from current directory check inside TDir folder
filename =".docx" # All word ducuments
find(path, filename)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!