Imports System.IO
Module Module1
Sub DeleteFiles(ByVal Dir As String)
Dim DirObj As New DirectoryInfo(Dir)
Dim Files As FileInfo() = DirObj.GetFiles("*.bak")
Dim Dirs As DirectoryInfo() = DirObj.GetDirectories("*.*")
Dim Filename As FileInfo
For Each Filename In Files
Try
File.Delete(Filename.FullName)
Console.WriteLine("Deleted {0}", Filename.FullName)
Catch E As Exception
Console.WriteLine("Error deleting {0}", Filename.FullName)
Console.WriteLine("Error: {0}", E.Message)
End Try
Next
Dim DirectoryName As DirectoryInfo
For Each DirectoryName In Dirs
Try
DeleteFiles(DirectoryName.FullName)
Catch E As Exception
Console.WriteLine("Error accessing {0}", DirectoryName.FullName)
Console.WriteLine("Error: {0}", E.Message)
End Try
Next
End Sub
Sub Main()
DeleteFiles("C:\")
End Sub
End Module
|