'list2sort is the list containing all directorys and files in a specific path. The data is hold in a TYPE declarion called Files
'Direction true is for ascending, false is for descending
'direction2 is true for showing directory's first in the final list, false for first showing the files
'SortOn string is the type you would like to sort on. For this type you can use, Ftype, Fname, Fsize
sub sortlist(list2sort as list, direction as boolean, direction2 as boolean,SortOn as string) as list
dim dirlist as list
dim filelist as list
'split the list into to files and directories
for i=0 to list2sort.size-1
dim f as files
f = list2sort.get(i)
select f.ftype
case "dir"
dirlist.add(f)
case else
filelist.add(f)
end select
next
'sort both lists using the specified direction
dirlist.sorttype(SortOn, direction)
filelist.sorttype(sortOn, direction)
' Based on direction2 show files or directory's first. True for directory first, false for files first
select direction2
case true
'first insert the directories into the list2sort list
for i=0 to dirlist.size-1
dim f as files
f=dirlist.get(i)
list2sort.InsertAt(i, f)
next
'now insert the files into the list2sort list
for i=0 to filelist.size-1
dim f as files
f=filelist.get(i)
list2sort.insertat(i+(dirlist.size-1), F) 'add the dirlist size to get the next position to write on. Else you would overwrite previous data
next
case false
'First insert the files into the list2sort list
for i=0 to filelist.size-1
dim f as files
f=filelist.get(i)
list2sort.insertat(i, F)
next
'now insert the directories into to list2sort list
for i=0 to dirlist.size-1
dim f as files
f=dirlist.get(i)
list2sort.InsertAt(i+(filelist.size-1), f)
next
end select
'return the sorted list
return list2sort
end sub