how to sort the directories?

chidambaram

Well-known member
Joined
Dec 27, 2007
Messages
62
Location
Chennai,India
Programming Experience
Beginner
Hi all,

i am working in VB.NET 2003

I want to sort the directories in ascending order.

i get the directories using
VB.NET:
        Dim di1 As IO.DirectoryInfo
        Dim dirfiles As New IO.DirectoryInfo(indesignfolder)
        Dim dirf1 As IO.DirectoryInfo() = dirfiles.GetDirectories()
        For Each di1 In dirf1
            MsgBox(di1.Name)
        Next

there is a sort function in dirf1.

how can i use this sort function to sort the directories in ascending order?


Thanks in advance....
 
There are various ways to sort an array. You'd have more choices in .NET 2.0 or later, thanks to generics, but here's one that will work for you:
VB.NET:
Dim names(dirf1.GetUpperBound(0)) As String

For index As Integer = 0 To names.GetUpperBound(0)
    names(index) = dirf1(index).Name
Next

Array.Sort(names, dirf1)
 
Back
Top