try:
    lst = os.listdir(path)
except OSError:
    pass
else:
    for name in lst:
        fn = os.path.join(path, name)
if os.path.isdir(fn):
    tree['children'].append(make_tree(fn))
else:
    pass
How to generate an html directory list using Python