countFiles(path)
Write the recursive function countFiles(path), which takes a string specifying a path to a folder and returns the total number of files in that folder (and all its subfolders). Do not count folders (or subfolders) as files. Do not worry if the supplied path is not valid or is not a folder.
To help test your code, here are some assertions for use with sampleFiles:
assert(countFiles("sampleFiles/folderB/folderF/folderG") == 0)
assert(countFiles("sampleFiles/folderB/folderF") == 0)
assert(countFiles("sampleFiles/folderB") == 2)
assert(countFiles("sampleFiles/folderA/folderC") == 4)
assert(countFiles("sampleFiles/folderA") == 6)
assert(countFiles("sampleFiles") == 10)
Note: regarding efficiency, it is overtly inefficient to create a list of any kind in your solution to this problem. In particular, you may not do this:
def countFiles(path):
return len(listFiles(path))