If I understood what you want correctly, the Sriram Sakthivel code sets part of what is required but cannot deliver what you want.
For Each folderinfo In BubbleSort_List(Folders, "Name")
MsgBox(folderinfo.Name)
Next
You have to set a string-type argument with the name of the target property ("Name", "CreationTime", etc.), and retrieve this property from one of the list items (the first one, for example) via GetProperty
; bear in mind that the LINQ query refers to the items, not to the whole list.
Private Function BubbleSort_List(list As List(Of IO.DirectoryInfo), propName As String) As List(Of IO.DirectoryInfo)
Dim curProperty As PropertyInfo = list(0).GetType().GetProperty(propName)
Return list.Select(Function(s) New With { _
Key .OrgStr = s, _
Key .SortStr = System.Text.RegularExpressions.Regex.Replace( _
s.Name, "(\d+)|(\D+)", _
Function(m) m.Value.PadLeft(list.Select(Function(folder) DirectCast(curProperty.GetValue(folder, Nothing), String).Length).Max(), _
If(Char.IsDigit(m.Value(0)), " "c, Char.MaxValue))) _
}).OrderBy(Function(x) x.SortStr).Select(Function(x) x.OrgStr).ToList
End Function
NOTE: I am just proposing a correction of your code to allow you to get what you want as I understood it. I am not recommending to rely on Reflection
by default (.GetValue
is pretty slow).