Whereas Python’s os.listdir("mydirectory")
will list both sub-files and sub-directories, you can use this simple list comprehension:
parent_folder = "myfolder" sub_directories = [ filename for filename in os.listdir(parent_folder) if os.path.isdir(os.path.join(parent_folder, filename)) ]
which will only list sub-directories of the parent_fodler