I've been using a modified version of this:
I'm using this code in a script transform. Original binding is to a dataset containing path data. ex: "A/B/C"
items = []
for row in range(value.rowCount):
path = value.getValueAt(row, 0)
current = items
for part in path.split("/"):
# Check if the current folder exists in our items list
folderExists = False
for itemsPointerItem in current:
if part == itemsPointerItem['label']:
folderExists = True
current = itemsPointerItem['items']
if not folderExists:
item = {
"label": part,
"expanded": False,
"items": [],
"data": path,
"icon": {
'path': 'material/stop',
'color': 'red',
'style': {}
}
}
current.append(item)
current = item['items']
return items