Question: Python: Recursively find maximum depth of directory tree, that is the deepest level of nesting that occurs within the folder structure. For example: a USB

Python: Recursively find maximum depth of directory tree, that is the deepest level of nesting that occurs within the folder structure.

For example: a USB drive has four levels of folders at its largest depth due to the folder F:\Folder 1\Folder 2\Folder 3.

Folder 3 has depth one since it only contains files, the folder F:\Folder 1\Folder2 has depth 2 since it contains a folder of depth 1. Then F:\Folder 1 has depth 3 since it contains a folder of depth 2 and no other folder which is deeper. So the depth of a folder is one more than the depth of the deepest folder it contains. A folder which is empty or only contains files, has depth 1. If the path is to a file, the depth is 0

Without using os.walk, write a function that takes a file path (as string) as an argument that recursively travels the directory to find the maximum depth of the tree.

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!