5
0

utils.py 293 B

123456789101112
  1. import os
  2. def get_directory_tree(path):
  3. tree = {'name': path}
  4. if os.path.isdir(path):
  5. tree['type'] = 'directory'
  6. tree['children'] = [get_directory_tree(os.path.join(path, child)) for child in os.listdir(path)]
  7. else:
  8. tree['type'] = 'file'
  9. return tree