Get list of Folders in directory path – Python

Print Directory List in Python

To get list of sub-directories present in a computer folder, use the code below.

Edit the folder path mentioned in the variable “folder_path”. Then execute this ready to use code.

It will print the sub-directories name one by one.

#List all subdirectories in a folder
#import libraries
import os,sys

#Program Start
print("Program Start")

#Enter Folder Path
folder_path = "D:/"

#Get directory names to a list
directory_list = next(os.walk(folder_path))[1]

#Read directory one by one
for director_name in directory_list:

#Program End
print("Program Complete")