在上一个模块的基础上改了一下,花了几分钟。虽然简单,但是比较有用,就当是代码收集:
Public Sub DelDirectory(ByVal DirName As String)
'If Not (Microsoft.VisualBasic.Right(destDirName, 1) = Path.DirectorySeparatorChar) Then
' ''取目标数程序,最后一个字符是否是“/”,不是则加上
' destDirName = destDirName + Path.DirectorySeparatorChar
'End If
Try
Dim files As String() = Directory.GetFiles(DirName)
For Each strfile As String In files
File.Delete(strfile) '删除文件
Next
Dim dirs As String() = Directory.GetDirectories(DirName)
For Each mydir As String In dirs
DelDirectory(mydir) ''递归遍历
Directory.Delete(mydir) '''删除此目录
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub