Answered step by step
Verified Expert Solution
Link Copied!

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 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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logidata+ Deductive Databases With Complex Objects Lncs 701

Authors: Paolo Atzeni

1st Edition

354056974X, 978-3540569749

More Books

Students also viewed these Databases questions

Question

=+2. How much staff time will it take to implement this tactic?

Answered: 1 week ago

Question

8. Explain the contact hypothesis.

Answered: 1 week ago

Question

7. Identify four antecedents that influence intercultural contact.

Answered: 1 week ago