I have some code I will give you that does recursive directory and file
searches. You can pass the function a wildcard.
'*******************************
'*
'* Shawn Shelton
'* This will search directories for files and directories.
'* May be recursive if told to.
'* Use wildcards for searching such as * or .exe
'*
Option Explicit On
Option Strict On
Imports System
Imports System.IO
Imports System.Collections
Module Searcher
Public Sub SearchDirectoryForFiles(ByVal dirlist As Stack, ByVal
searchPath As String, ByVal RecurseDirs As Boolean)
' Split searchPath into a directory and a wildcard specification.
'
Dim directoryPath As String = Path.GetDirectoryName(searchPath)
Dim search As String = Path.GetFileName(searchPath)
Dim dir As New DirectoryInfo(directoryPath)
If directoryPath Is Nothing Or search Is Nothing Then
Return
End If
Dim f As FileInfo
Try
For Each f In dir.GetFiles(search)
dirlist.Push(f.FullName)
Next
Catch e As UnauthorizedAccessException
Return
Catch e As DirectoryNotFoundException
Return
End Try
' Now that you have finished the files in this directory, recurse for
' each subdirectory.
If RecurseDirs = True Then
Dim directories As String() = Directory.GetDirectories(directoryPath)
Dim d As String
For Each d In directories
SearchDirectoryForFiles(dirlist, Path.Combine(d, search), True)
Next d
End If
End Sub
Public Sub SearchDirectoryForDirectories(ByVal dirList As Stack, ByVal
searchPath As String)
Dim directoryPath As String = Path.GetDirectoryName(searchPath)
Dim directories As String() = Directory.GetDirectories(directoryPath)
Dim d As String
For Each d In directories
dirList.Push(d)
SearchDirectoryForDirectories(dirList, d & "\")
Next d
End Sub
End Module
****************************
Call it like this:
dim dirlist as stack
dim x as string
SearchDirectoryForFiles(DirList, "c:\winnt\*.txt", False)
If DirList.Count > 0 Then
For Each x In DirList
SetAttr(x, FileAttribute.Normal)
File.Delete(x)
Next
End If