Finding files based on date and time

Posted on 2006-04-13
Last Modified: 2010-04-23

Re: 2003

I was wondering if anyone knew of a way to find files in a specified location based on their date and time, without recursively having to loop round the directory and it's subs, checking each file individually.  I need to quickly put together a simple directory/file scan/backup app for a small network and would hope it can reasonably easily be accomplished using VB.NET

I've been through the help files and Google'd until I can Google no more and am now stumped.

Any and all replies appreciated.

Question by:onedunpark

    Expert Comment

    I really don't think so. The date/time of when the file was created of modified is part of the file properties and is not stored anywhere else. Even the windows search assistant and to iterate throught the folders etc.

    Author Comment

    Thanks for the reply.  I had hoped against this and already have a straightforward recursive routne written.  I'd just like to have avoided it.

    I'll hold off a wee bit to see if there are other replies and if not, the points are yours.

    LVL 14

    Accepted Solution

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim arFiles As ArrayList = FindFilesByDate("c:\program files", Now.AddDays(-10), Now)

        End Sub

        Public Function FindFilesByDate(ByVal Folder As String, ByVal dtStart As Date, ByVal dtEnd As Date) As ArrayList
            Dim arResult As New ArrayList

            For Each sFilename As String In My.Computer.FileSystem.GetFiles(Folder, FileIO.SearchOption.SearchAllSubDirectories, "*.*")

                Dim fi As New FileInfo(sFilename)
                If fi.LastWriteTime <= dtEnd And fi.LastWriteTime >= dtStart Then
                End If


            Return arResult
        End Function

    This works in Visual Studio 2005, but somehow it doesnt seem faster to me than iterating yourself :D

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 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

    16 Experts available now in Live!

    Get 1:1 Help Now