1
0
Fork 0
mirror of https://github.com/mmumshad/ansible-playable.git synced 2025-02-13 12:51:50 +00:00
ansible-playable/helpers/dir_tree.py

15 lines
412 B
Python

import os
import json
def path_to_dict(path):
d = {'name': os.path.basename(path),'path': os.path.abspath(path)}
if os.path.isdir(path):
d['type'] = "directory"
d['children'] = [path_to_dict(os.path.join(path,x)) for x in os.listdir\
(path)]
else:
d['type'] = "file"
filename, d['extension'] = os.path.splitext(path)
return d
print json.dumps(path_to_dict('.'))