I have a path to a certain directory, and I need to get a list of all of it's sub-directories that themselves don't contain any sub-directories.
For example, if I've got the following tree:
-father_dir:
-son_dir1:
-grandson.txt
-son_dir2:
-grandson_dir1:
-greatgrandson1.txt
I'd like to have a list containing: [son_dir1, grandson_dir1]
What I tried: I used os.walk()
to get all of the sub-directories in father_dir
, and now I'm trying to iterate over each sub-directory's contents (with os.listdir()
) and find if it contains directories... so far I wasn't successful (as os.listdir()
doesn't give the path to the directory but rather only its name), besides it seems to be a very cumbersome method.
Any simple solution would be welcome. Thanks!