BobAchgill said:
How can I sort the contents of Directory.GetCurrentDirectory() by file
create
data?
If that is not possible how can I sort it by file name?
\\\
Public Class LastWriteTimeComparer
Implements IComparer
Public Function Compare( _
ByVal x As Object, _
ByVal y As Object _
) As Integer Implements IComparer.Compare
Return _
Math.Sign( _
File.GetLastWriteTime(DirectCast(x, String)).Ticks - _
File.GetLastWriteTime(DirectCast(y, String)).Ticks _
)
End Function
End Class
///
Usage:
\\\
Dim FileNames() As String = Directory.GetFiles("C:\WINDOWS")
Array.Sort(FileNames, New LastWriteTimeComparer())
Me.ListBox1.DataSource = FileNames
///
Alternatively you may want to take a closer look at LINQ, which provides an
ability to order the items.