Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Because of your success implementing features in the 'userfeedback' module, you've decided to branch out and add a core feature to the shell. Write
a recursive function numoccurrences 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
Hint: this problem is very similar to the search and countfiles 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 codesamples.zip in Week of the
Content page. That is reproduced below for your convenience.
test
dubioustxt
simple.py
test.txt
test
dubioustxt
simple.py
test.txt
test
dubioustxt
simple.py
test
dubioustxt
simple.py
test
empty.txt
Sample usage is below:
numoccurrences
simple.py 'test'
numoccurrencesemptytxt 'test'
numoccurrences
simple.py 'testtest
numoccurrencesdoesnotexist.py 'testtest
numoccurrences
simple.py 'doesnotexistdirectory
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started