I have been using 'find' to output the directory structure from the root down and I don’t mind that it takes a while. My problem is that I want to cut down on the redundant info of repeating every files path, I want to output the files in JSON format.
I need to be able to run this from the termin, i can not be creating python files etc on the box.
For example, this:
root
|_ fruits
|___ apple
|______images
|________ apple001.jpg
|________ apple002.jpg
|_ animals
|___ cat
|______images
|________ cat001.jpg
|________ cat002.jpg
Would become something like....
{"data" : [
{
"type": "folder",
"name": "animals",
"path": "/animals",
"children": [
{
"type": "folder",
"name": "cat",
"path": "/animals/cat",
"children": [
{
"type": "folder",
"name": "images",
"path": "/animals/cat/images",
"children": [
{
"type": "file",
"name": "cat001.jpg",
"path": "/animals/cat/images/cat001.jpg"
}, {
"type": "file",
"name": "cat001.jpg",
"path": "/animals/cat/images/cat002.jpg"
}
]
}
]
}
]
}
]}
File "", line 1
print(json.dumps(path_hierarchy(directory), indent=2, sort_keys=True))
^
IndentationError: unexpected indent
– Fearghal Oct 28 '14 at 15:30