1# accepts any number of paths,
2# returns the total amound of files (not dirs) that are in the given paths
3# looks recursively
4
5def countFiles(*paths):
6 """
7 :param paths: list of all paths, the number of files are added
8 :return: return the number of files (not directories) in the folders recursively (subfolders are checked as well)
9 """
10 def helper(path: str):
11 count = 0
12 # iterate through all files and dir names in path
13 for fileName in os.listdir(path):
14 filePath = join(path, fileName)
15 if isfile(filePath): # if file, increment
16 count += 1
17 elif isdir(filePath): # if dir, recursively count files in dir
18 count += helper(filePath)
19 return count
20
21 numFiles = 0
22 for path in paths:
23 numFiles += helper(path)
24 return numFiles