Suppose I am currently at a directory named current_dir which has the directory structure in linux as shown above. This directory has sub directories which further have sub directories and so on.
I want to create a file at the end of last level of each directory, i.e., at directories b and c which are the last level directories in first and similarly at directories e and f which are the last level directories in second. I am given the path to the current_dir directory only.
I was trying out with this code:-
path = os.walk('/current_dir')
for root, directories, files in path:
for directory in directories:
But the problem here is that I am not able to figure out how to use the directory variable inside the 2nd for loop to check whether it is the last directory or not. How could I do that?