Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to find and sort files based on creation time

Total Hit ( 6601)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The following code will sort file list based on CreationTime

Click here to copy the following block
Option Explicit On
Option Strict On

Imports System.Collections
Imports System.IO


Module Module1


  Private Class CreateTimeComparer
    Implements IComparer

    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare
      ' make it return this in descending order (newest first)
      Return -DateTime.Compare(DirectCast(x, FileInfo).CreationTime, DirectCast(y, FileInfo).CreationTime)
    End Function
  End Class


  Sub Main()
    Dim al As New ArrayList
    Dim files() As String = Directory.GetFiles("c:\windows\system32")
    Dim comparer As New CreateTimeComparer


    ' create a list of file info objects
    For Each file As String In files
      al.Add(New FileInfo(file))
    Next


    ' sort the array list using the custom comparer
    al.Sort(comparer)


    ' print them out
    For Each fi As FileInfo In al
      Console.WriteLine(fi.CreationTime)
      Console.ReadLine()
    Next
  End Sub


End Module


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.