Created
February 28, 2017 03:07
-
-
Save mnaser/5832b9278e7b7d91f51d6735a09de6ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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