VB Code:
Private Sub SortIt()
' Here I get the folder info
Dim dr As New DirectoryInfo("D:\test")
' if the folder exists then get the txt files in an array
If dr.Exists Then
Dim ff() As FileInfo
ff = dr.GetFiles("*.txt")
' if any file exist then sort them according to their property i set in compclass
If ff.Length > 0 Then
Array.Sort(ff, New compclass(SortOrder.Descending))
' some code here to deal with the sorted array
End If
End If
End Sub
Public Class compclass
Implements IComparer
Private srt As SortOrder
Public Sub New(ByVal srtorder As SortOrder)
srt = srtorder
End Sub
Public Function compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
If srt = SortOrder.Descending Then
Return (DateTime.Compare(CType(x, FileInfo).CreationTime, CType(y, FileInfo).CreationTime) * (-1))
Else
Return DateTime.Compare(CType(x, FileInfo).CreationTime, CType(y, FileInfo).CreationTime)
End If
' Here you can use your objects, and the code to compare will be like
'Return Typeyouwanttocompare.Compare(CType(x, myObject).myProperty, CType(y, myObject).myProperty)
End Function
End Class