List files and sub-directories

The listdir() function outputs all files and subfolders in a list. If no parameter is passed to the function, all files and subfolders of the current path are output. However, another path can also be specified.

import os

path = "/path/directory-name"

directories = os.listdir(path)
print(directories)
Output
List of files and subdirectories in the specified path