I am trying to build a function that converts a list of paths into a object as below; the output of the script should be structured as below.
Output
data = [
{
"type": "folder",
"name": "dir1",
"children": [
{
"type": "folder",
"name": "photos",
"children": [
{
"type": "file",
"name": "mydir1.pdf",
},
{
"type": "file",
"name": "yourdir1.pdf",
}
]
}
]
}
And input is like this
paths = [
"dir1/photos/mydir1.pdf",
"dir1/photos/yourdir1.pdf"
]
2
Answers
You can try below function:
You can build tree with the help of object reference.