def cats_and_subs(root='notes'):
    """
    Collect categories and subcategories.
    """
categories = [d for d in os.listdir(root) if isdir(join(root, d))]
sub_categories = []
for c in categories:
    sub_categories += [d for d in os.listdir(
        join(root, c)) if isdir(join(root, c, d))]
return categories, sub_categories
if __name__ == '__main__':
    pass
How to parse a directory tree in python?