pth = '/path/to/notes'

def getCats(pth):
    cats = []
subcats = []
for dirpath, dirnames, filenames in os.walk(pth):
    if dirpath == pth:
        cats = dirnames
else:
    subcats.extend(dirnames)
dirnames[:] = []
return cats, subcats
How to parse a directory tree in python?