[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 122
  • Last Modified:

how to sort folders read out recursively

In order to to build up a menu structure i read out a special folders with all its subfolders recursively. Now the problem is, that they are unsortet, better, i can't see where the parent folders of them. Example:
Folder1 ->Subfolder1 ->SubSubfolder1
                     ->SubSubfolder2
        ->Subfolder2 ->sSubfolder1
                     ->sSubfolder2
now the result of my recursive search is
SubSubfolder1, SubSubfolder2, Subfolder1, sSubfolder1, sSubfolder2, Subfodler2, Folder1
Now i want to mark them eg like this:
f1s1SubSubfolder1, f1s1SubSubfolder2, f1Subfolder1, f1s2SubSubfolder1, f1s2SubSubfolder2, f1Subfolder2, Folder1.
Does anybody know how to do this??
0
evilT
Asked:
evilT
  • 2
  • 2
1 Solution
 
TimCotteeCommented:
Could you post the code you are using to generate the recursed list, then perhaps I can see a way to sort it.
0
 
evilTAuthor Commented:
 <%
  function getsubfolders(path)
  Dim fso, f, f1, s, sf
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.GetFolder(path)
  Set sf = f.SubFolders
  For Each f1 in sf
      pfad = path&"\"&f1.name
      getsubfolders(pfad)
      response.write(f1.name & " ")
  Next
  end function
  %>

By the way: i use it in an asp - page
0
 
TimCotteeCommented:
First thing is that you should move the response.write to before the getsubfolders call, this will put your parent at the top of the list.

Try This, it is not quite the prefixing structure you suggest but is probably clearer especially if there are more than two levels.

Function getsubfolders(path, prefix)
    Dim fso, f, f1, s, sf
    Dim fnum As Integer
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(path)
    Set sf = f.SubFolders
    For Each f1 In sf
        fnum = fnum + 1
        pfad = path & "\" & f1.Name
        Response.Write(prefix & CStr(fnum) & ":" & f1.Name & " ")
        getsubfolders pfad, prefix & CStr(fnum) & ":"
    Next
End Function
 
0
 
evilTAuthor Commented:
Hey cool, i think thats exactly what i wanted, thx a lot
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now