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
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