Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving Files sorted by Date order 2

Status
Not open for further replies.

HouDog

Programmer
Aug 14, 2003
54
CA
Hi all,

I am trying to write a program that when it starts up, it retrieves the contents of a folder in ascending datetime order. I looked at the Dir() function but it doesn't do what I need. I was just wondering if anyone knew of a way before I explore a sorting algorithm solution. Thx.
 
Not sure if there isn't a better way but this will work:

Public Class SortFiles
Implements IComparer

Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
Dim f1 As FileInfo = DirectCast(x, FileInfo)
Dim f2 As FileInfo = DirectCast(y, FileInfo)
Return f1.CreationTime.CompareTo(f2.CreationTime)
End Function
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim di As DirectoryInfo = New DirectoryInfo("c:\")
Dim files() As FileInfo = di.GetFiles
Array.Sort(files, New SortFiles)
 
Thanks John, that worked great. Thanks again for your response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top