My program performs a search on a user selected directory and produces a list of files and attributes in a listview. The user then has the option to open files, move them, or delete them. This program will be used accross a wide variety of users and I want to be able to filter the results so people don't end up deleting system files that are necessary for their computer to function. Is there a way to search for all files types EXCEPT a list of system extensions? Below is the code (a little abbreviated) used to perform the search when the user clicks the "Search" button - the wantedFiles variable is a string identified as "*.*"

Public Sub SearchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBtn.Click
            Dim dirInfo As New DirectoryInfo(DirSearchTxtBox.Text)
            Dim wantedFiles As String = "*.*"
            Dim CutOffDate As Date = DateTimePicker1.Text
            'call method that searches and puts files in list
            FilesSearch(dirInfo, wantedFiles, CutOffDate, FilesList)
End Sub
Public Sub FilesSearch(ByVal dirInfo As DirectoryInfo, ByVal wantedFiles As String, ByVal CutOffDate As Date, ByVal List As ListView)
       Dim resultFiles() As FileInfo
            resultFiles = dirInfo.GetFiles(wantedFiles)
            For Each resultFile As FileInfo In resultFiles
                If resultFile.LastWriteTime.Date < CutOffDate Then
                    Dim colItem(4) As String
                    Dim attributes As ListViewItem
                    colItem(0) = (resultFile.Name) 'name of file in check box list 
                    colItem(1) = (resultFile.DirectoryName) 'full directory path and file name
                    colItem(2) = (resultFile.LastAccessTime) 'last access time of files
                    colItem(3) = (resultFile.Length / 1000) 'file size in KB
                    attributes = New ListViewItem(colItem)
                    FilesList.Items.Add(attributes)

                    'automatically size columns based on content or header
                    Dim col1content = attributes.Text.Length
                    Dim col1header = 100
                End If
            Next resultFile
            Dim SubDirs() As DirectoryInfo = dirInfo.GetDirectories()
            For Each SubDir As DirectoryInfo In SubDirs
                FilesSearch(SubDir, wantedFiles, CutOffDate, List)
            Next SubDir
End Sub

Can I create a separate file of some kind with a list of extensions and have a variable be identified as anything but items in the file? Or is there an easier way to do it? I'm kind of new to .net - any advice or feedback is welcome! Thanks!

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.