I have a requirement to find a nested hierarchy of directory inside a base directory structure.
Lets say my base directory in which I want to find is : /home/user/my_base_dir
And the directory that I want to find inside it is : log_dir
I have written tried below code which is working:
import glob
import os
base_dir = "/home/user/my_base_dir"
to_find = base_dir + "/*/log_dir"
for dir_path in filter (os.path.exists, glob.iglob(to_find)):
print ("Found = ", dir_path)
The problem with this is , in this case I am assuming that it will be available underneath one directory level (which is the *) as : */log_dir
But what is the way to find it under any nested hierarchy of the base_dir for which I do not know how to build the regex.
Thanks