I am new to VB and am trying to create a program that will search for files in a user specified directory within a specified date range, and then list the files in a list view. I've managed to figure most of it out except how to specify the date range I want.
Simplified a bit, this is what I have:

Private Sub SearchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBtn.Click
        Dim dirInfo As New DirectoryInfo(DirSearchTxtBox.Text)
        Dim CutOffDate As Date = Date.FromOADate(4 / 1 / 2008)
        FilesSearch(dirInfo, CutOffDate, FilesList)
    End Sub
Public Sub FilesSearch(ByVal dirInfo As DirectoryInfo, ByVal CutOffDate As Date, ByVal List As ListView)
Dim resultFiles() As FileInfo
            resultFiles = dirInfo.GetFiles(CutOffDate)

            For Each resultFile As FileInfo In resultFiles
                Dim colItem(5) As String
                Dim attributes As ListViewItem
                colItem(0) = (resultFile.Name) 
                colItem(1) = (resultFile.DirectoryName) 
                colItem(2) = (resultFile.LastAccessTime) 
                colItem(3) = (resultFile.Length / 1000) 
                colItem(4) = (resultFile.Attributes) 
                attributes = New ListViewItem(colItem)
                FilesList.Items.Add(attributes)
             Next resultFile

            Dim SubDirs() As DirectoryInfo = dirInfo.GetDirectories()
            For Each SubDir As DirectoryInfo In SubDirs
                FilesSearch(SubDir, CutOffDate, List)
            Next SubDir
End Sub

I want the search to produce all files that are older than 2 years, and maybe provide a field where the user can specify a date, and then the search would find all files older than the date they enter. Any help is greatly appreciated!

Try this:

Imports System.IO

Public Class Form1

    Private Sub SearchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBtn.Click
        Dim dirInfo As New DirectoryInfo(DirSearchTxtBox.Text)
        Dim CutOffDate As Date = "#6 / 1 / 2008#"        
        FilesSearch(dirInfo, CutOffDate, FilesList)
    End Sub

    Public Sub FilesSearch(ByVal dirInfo As DirectoryInfo, ByVal CutOffDate As Date, ByVal List As ListView)
        Dim resultFiles() As FileInfo
        resultFiles = dirInfo.GetFiles()

        For Each resultFile As FileInfo In resultFiles
            If resultFile.CreationTime.Date < CutOffDate Then
                Dim colItem(5) As String
                Dim attributes As ListViewItem
                colItem(0) = (resultFile.Name)
                colItem(1) = (resultFile.DirectoryName)
                colItem(2) = (resultFile.LastAccessTime)
                colItem(3) = (resultFile.Length / 1000)
                colItem(4) = (resultFile.Attributes)
                attributes = New ListViewItem(colItem)
                FilesList.Items.Add(attributes)
            End If
        Next resultFile

        Dim SubDirs() As DirectoryInfo = dirInfo.GetDirectories()
        For Each SubDir As DirectoryInfo In SubDirs
            FilesSearch(SubDir, CutOffDate, List)
        Next SubDir
    End Sub


End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.