11-25-2014, 05:22 AM
A final hurdle I need to take is the sorting of the generated menu.
Is it possible to sort the menu just like windows sorts it's folder contents on name:
- First display at the top folders (From a to z)
- Then below the folders, display the files (From a to z)
I hoped the below code would get me somewhere but it does not work like I wished it would.
Is it even possible? I can imagine this is very complex.
Function ShowMenuStringFromFilesInFolder
Is it possible to sort the menu just like windows sorts it's folder contents on name:
- First display at the top folders (From a to z)
- Then below the folders, display the files (From a to z)
I hoped the below code would get me somewhere but it does not work like I wished it would.
Is it even possible? I can imagine this is very complex.
Function ShowMenuStringFromFilesInFolder
;/
function $folderFiles str&sm ARRAY(str)&aPaths
;Creates string for ShowMenu from matching files in a folder and its subfolders.
;folderFiles - folder and filename wildcard string. See example.
;sm - receives string that can be passed to ShowMenu.
;aPaths - receives full paths of matching files.
;EXAMPLE
;str sm; ARRAY(str) a
;ShowMenuStringFromFilesInFolder "$documents$\*.txt" sm a
;int i=ShowMenu(sm)-1; if(i<0) ret
;out a[i]
sm.all
aPaths=0
int k level; str rel relPrev
// ---- ORIGINAL
;Dir d
;foreach(d folderFiles FE_Dir 4)
// ----
//---- REPLACED
ARRAY(str) a; int i
GetFilesInFolder a "$desktop$" "*.rtf" 4
a.sort(8)
for i 0 a.len
,Dir d.dir(a[i])
//----
,rel=d.RelativePath
,k=d.Level
,;out "%i %s" k rel
,
,;end submenu if need (insert "<" line)
,if level
,,for(level level k -1) sm.formata("%.*m<[]" level 9)
,,;may be in other folder
,,for level level 0 -1
,,,if(!StrCompareN(rel relPrev findt(rel level "\"))) break
,,,sm.formata("%.*m<[]" level 9)
,relPrev=rel
,
,;begin submenu if need (insert ">Folder" line)
,for level level k
,,_s.gett(rel level "\")
,,sm.formata("%.*m>%s[]" level 9 _s)
,
,;add normal item, with id = aPaths index + 1
,aPaths[]=d.FullPath
,sm.formata("%.*m%i %s[]" k 9 aPaths.len _s.getfilename(rel))
rep(level) sm.formata("%.*m<[]" level 9); level-1