I'm able to list the directories and files using the below code
for root, dirs, files in os.walk(startpath):
level = root.replace(startpath, '').count(os.sep)
indent = ' ' * 4 * (level)
print('Directory -> {}{}/'.format(indent, os.path.basename(root)))
subindent = ' ' * 4 * (level + 1)
for f in files:
if not f.startswith('.'):
print('file -> {}{}'.format(subindent, f))
I need only directories and nested directories to be stored in a format so that I can show that on UI