Skip to content

Instantly share code, notes, and snippets.

@mnaser
Created February 28, 2017 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnaser/5832b9278e7b7d91f51d6735a09de6ca to your computer and use it in GitHub Desktop.
Save mnaser/5832b9278e7b7d91f51d6735a09de6ca to your computer and use it in GitHub Desktop.
import json
import os
import sys
path = sys.argv[1]
def generate_tree(path):
tree = []
dentries = os.listdir(path)
for d in dentries:
full_path = os.path.join(path, d)
node = {
'text': d,
'href': '#%s' % d
}
if os.path.isdir(full_path):
node['nodes'] = generate_tree(full_path)
else:
node['icon'] = 'fa fa-file-o'
tree.append(node)
return tree
tree = generate_tree(path)
print json.dumps(tree, sort_keys=True, indent=4, separators=(',', ': '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment