Question: Problem 4 Because of your success implementing features in the 'user - feedback' module, you've decided to branch out and add a core feature to

Problem 4
Because of your success implementing features in the 'user-feedback' module, you've decided to branch out and add a core feature to the shell. Write
a recursive function num_occurrences (filename, path) that counts the number of times the file filename appears in the directory pointed at by
path or any of its subdirectories. The function should return that count. If the filename OR the path do not exist, your function should return 0.
Hint: this problem is very similar to the search () and count_files () examples we did in class. Is there any way you can combine the approaches
of those two exercises to solve this problem?
For the example usage, assume that we're using the same directory structure that was provided as part of code_samples.zip in Week 7 of the
Content page. That is reproduced below for your convenience.
test
dubious1.txt
simple.py
test.txt
test1
dubious2.txt
simple.py
test.txt
test2
dubious1.txt
simple.py
test3
dubious2.txt
simple.py
test4
empty.txt
Sample usage is below:
num_occurrences('
simple.py', 'test')
4
num_occurrences('empty.txt', 'test')
1
num_occurrences('
simple.py', 'test/test2')
2
num_occurrences('does_not_exist.py', 'test/test1')
0
num_occurrences('
simple.py', 'does_not_exist/directory')
0
 Problem 4 Because of your success implementing features in the 'user-feedback'

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 Databases Questions!