I should do it wiht only import os
I have problem, that i don't know how to make program after checking the specific folder for folders to do the same for folders in these folders and so on.
I should do it wiht only import os
I have problem, that i don't know how to make program after checking the specific folder for folders to do the same for folders in these folders and so on.
The quickest way is using os.walk
like this:
import os
path = '.'
folder_paths = [
paths[0] for paths in os.walk(path)
]
print(folder_paths)
If you need a custom recursive function you can use os.listdir
and os.path.isdir
instead:
def print_sub_dirs(path):
folder_paths = [
os.path.join(path, folder) for folder in os.listdir(path) if os.path.isdir(os.path.join(path, folder))
]
for folder_path in folder_paths:
print(folder_path)
print_sub_dirs(folder_path)
print_sub_dirs('.')