Solved

vb.net: list 10 most recent files

Posted on 2004-05-01
5
559 Views
Last Modified: 2012-08-14
I have a directory with a lot of .log files, one for each day

how do I list just the 10 most recent files by file creation date, or, in other words, the files for the last 10 days?
0
Comment
Question by:kapcreations
  • 2
5 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 10969058
Hi kapcreations:
I would start with code like this:

    Dim DirInfo As New System.IO.DirectoryInfo("")
    Dim Files() As System.IO.FileInfo = DirInfo.GetFiles("*.log")
    For Each f As IO.FileInfo In Files
         Save(f.Name, f.CreationTime())
    Next

Within Save you can create a SortedList and then keep only the most recent 10


Dabas
0
 
LVL 1

Author Comment

by:kapcreations
ID: 10969375
huh?  I have never done a sorted list before...
0
 
LVL 27

Accepted Solution

by:
Dabas earned 250 total points
ID: 10969428
kapcreations:
Ignore the For Each loop above and use this code instead:

        Dim sl As New SortedList
        For Each File As IO.FileInfo In Files
            sl.Add(File.CreationTime, File.Name) 'Add file to SortedList. SortKey is CreationTime
        Next

        Dim Count As Integer = 0
        For Each File As IO.FileInfo In sl 'Now show the sorted list in correct order
            MessageBox.Show(file.Name & " " & file.CreationTime.tostring)
        Next


Dabas
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now