Skip to content

Instantly share code, notes, and snippets.

@mnaser
Created February 28, 2017 03:07
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