?
Solved

Finding files based on date and time

Posted on 2006-04-13
3
Medium Priority
?
175 Views
Last Modified: 2010-04-23
Hi,

Re: VB.net 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.

Steven
0
Comment
Question by:onedunpark
3 Comments
 

Expert Comment

by:Vis781
ID: 16445409
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.
0
 

Author Comment

by:onedunpark
ID: 16448549
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.

0
 
LVL 14

Accepted Solution

by:
PockyMaster earned 375 total points
ID: 16449215
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
                arResult.Add(sFilename)
            End If

        Next

        Return arResult
    End Function

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses

601 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