Tips and tricks for .NET using ASP and VB code.

Class to sort files by ascending creation date

Dim DirectoryInfo As New IO.DirectoryInfo("C:\Temp\")
Dim FileInfoArray As IO.FileInfo() = DirectoryInfo.GetFiles("*.TXT")
Array.Sort(FileInfoArray, New clsCompareFileInfo)

Public Class clsCompareFileInfo
Implements IComparer
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
Dim File1 As IO.FileInfo
Dim File2 As IO.FileInfo
File1 = DirectCast(x, IO.FileInfo)
File2 = DirectCast(y, IO.FileInfo)
Compare = DateTime.Compare(File1.CreationTime, File2.CreationTime)
End Function
End Class

No comments:

Post a Comment

Search This Blog