Computing a hierarchical tree of files and folders
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Computing a hierarchical tree of files and folders
Based on the lesson https://lessons.livecode.com/m/4071/l/1 ... ers-part-2 I have a list of files in any depth starting from a root folder.
I would like to present files not with their full path, but as leaves to nodes and nodes as a tree.
The list I receive looks something like this (very long list of folders with files and subfolders with their files):
LPS_App/docs/Table Arrays_LPS.txt
LPS_App/docs/Text and Paragraph formats_LC.txt
LPS_App/docs/USE CASES PARTY.txt
LPS_App/docs/Access Privileges User Rights User Roles/USE CASES PARTY.txt
LPS_App/docs/Access Privileges User Rights User Roles/210412 2200 SQL Script changes for selection.txt
A tree would look like this, for example (or be tab delimited):
..| Root Folder
.....|-- File 1
.....|-- File 2
.....|-- File 3
.....|-- Another Folder
..........|-- File 4
..........|-- File 5
..........|-- File 6
I am kindly asking if there is a ready-made solution around to convert the path information into such hierarchical display that can be used in the datagrid, in tab-delimited fileds, or otherwise formatted.
Thanks in advance, Roland
I would like to present files not with their full path, but as leaves to nodes and nodes as a tree.
The list I receive looks something like this (very long list of folders with files and subfolders with their files):
LPS_App/docs/Table Arrays_LPS.txt
LPS_App/docs/Text and Paragraph formats_LC.txt
LPS_App/docs/USE CASES PARTY.txt
LPS_App/docs/Access Privileges User Rights User Roles/USE CASES PARTY.txt
LPS_App/docs/Access Privileges User Rights User Roles/210412 2200 SQL Script changes for selection.txt
A tree would look like this, for example (or be tab delimited):
..| Root Folder
.....|-- File 1
.....|-- File 2
.....|-- File 3
.....|-- Another Folder
..........|-- File 4
..........|-- File 5
..........|-- File 6
I am kindly asking if there is a ready-made solution around to convert the path information into such hierarchical display that can be used in the datagrid, in tab-delimited fileds, or otherwise formatted.
Thanks in advance, Roland
Re: Computing a hierarchical tree of files and folders
If you modify the source to generate a nested array, then the tree view widget could display the data fairly efficiently.
Another alternative is Trevor’s DataView Tree. He has an example that displays a folder hierarchy (GitHub.com/trevordevore/dataview_demo).
Someone may have a nifty way to parse your existing data.
Another alternative is Trevor’s DataView Tree. He has an example that displays a folder hierarchy (GitHub.com/trevordevore/dataview_demo).
Someone may have a nifty way to parse your existing data.
Brian Milby
Script Tracker https://github.com/bwmilby/scriptTracker
Script Tracker https://github.com/bwmilby/scriptTracker
Re: Computing a hierarchical tree of files and folders
Thank you Brian for the response.
Nested arrays is one way I am looking into. There is even a lesson I was not aware about.
Also I will look into Trevor's solution.
Just for an exercise, I was thinking about a purely list/text based solution without using arrays, but other things came in between. If I find the time, I will post.
https://lessons.livecode.com/m/4071/l/2 ... dable-form
Regards, Roland
Nested arrays is one way I am looking into. There is even a lesson I was not aware about.
Also I will look into Trevor's solution.
Just for an exercise, I was thinking about a purely list/text based solution without using arrays, but other things came in between. If I find the time, I will post.
https://lessons.livecode.com/m/4071/l/2 ... dable-form
Regards, Roland
-
- VIP Livecode Opensource Backer
- Posts: 9833
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Computing a hierarchical tree of files and folders
That Lesson is still useful for certain things, but since it was written LC now has a Tree widget which displays array contents in outline form in one step.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Computing a hierarchical tree of files and folders
Hi Brian
Reference to the link you gave: https://github.com/trevordevore/dataview_demo
The DataView Demo from Trevor looks phantastic. The file browser demo displays folders and files exactly what I had in mind.
I have to dig deeper into it to get a full picture.
Roland
Reference to the link you gave: https://github.com/trevordevore/dataview_demo
The DataView Demo from Trevor looks phantastic. The file browser demo displays folders and files exactly what I had in mind.
I have to dig deeper into it to get a full picture.
Roland
Re: Computing a hierarchical tree of files and folders
Hi Roland,golife wrote: ↑Thu Jul 08, 2021 4:51 pmI would like to present files not with their full path, but as leaves to nodes and nodes as a tree.
The list I receive looks something like this (very long list of folders with files and subfolders with their files):
LPS_App/docs/Table Arrays_LPS.txt
LPS_App/docs/Text and Paragraph formats_LC.txt
LPS_App/docs/USE CASES PARTY.txt
LPS_App/docs/Access Privileges User Rights User Roles/USE CASES PARTY.txt
LPS_App/docs/Access Privileges User Rights User Roles/210412 2200 SQL Script changes for selection.txt
I am kindly asking if there is a ready-made solution around to convert the path information into such hierarchical display that can be used in the datagrid, in tab-delimited fileds, or otherwise formatted.
Thanks in advance, Roland
Trevor's solution is undoubtedly superior, but if you want a quick solution using your existing data, it's a matter of splitting it into a multidimensional array, which was exactly a question Dick helped me with here: viewtopic.php?f=8&t=36071&p=206874#p206874. You can then pass this array to LiveCode's tree view widget, which would appear to be what you requested.
I've abstracted Dick's advice to a function generalisable for any text and work even if there are multiple duplicate keys (in your case directories) containing different values - just pass the text, the delimiter and if you wish the values to be numerically indexed (this is required if there are multiple identical keys with different values as they'll all overwrite each other otherwise).
Code: Select all
function compoundSplit pText, pDelimiter, assignIndexes
## if there are duplicate keys (lines) with different values, these need to be numerically keyed -> pass assignIndexes as true
local tArray, tValue, tSource, x
lock screen
filter pText without empty into tSource
set the itemDelimiter to pDelimiter
sort lines of tSource text ascending
repeat with i = 1 to the number of lines of tSource
if assignIndexes then // assign numeric indexes to values of duplicate keys
add 1 to x
put item 1 to -2 of line i of tSource & pDelimiter & x & pDelimiter & item -1 of line i of tSource into line i of tSource
if item 1 to -3 of line i of tSource <> item 1 to -2 of line i + 1 of tSource then
put 0 into x
end if
end if
put item 1 to -2 of line i of tSource into tArray // series of keys
put item -1 of line i of tSource into tValue // value
split tArray by pDelimiter
put tValue into it[tArray]
end repeat
return it
end compoundSplit
If you want to show the example text you post above in a tree view:
Code: Select all
set the arrayData of widget "tree view" to compoundSplit(text, slash, true)
Re: Computing a hierarchical tree of files and folders
@stam
Hello Stam
Sorry, I was out for the last weekend until today and did not reply.
That is really a very helpful comment with a code example and wanted to thank you very much.
In the next days, I will check it out carefully and if there is any thought that might make up a viable contribution, I will write.
Roland
Hello Stam
Sorry, I was out for the last weekend until today and did not reply.
That is really a very helpful comment with a code example and wanted to thank you very much.
In the next days, I will check it out carefully and if there is any thought that might make up a viable contribution, I will write.
Roland