Try this one:
Private Sub DeleteAllSubFolders(ByVal StartPath As String)
Dim myfolder As DirectoryInfo = New DirectoryInfo(StartPath)
Dim mySubfolders() As DirectoryInfo = myfolder.GetDirectories()
Dim strFiles() As FileInfo = myfolder.GetFiles()
'for each folder, do a recursive call to this sub routine
For Each myItem As DirectoryInfo In mySubfolders
DeleteAllSubFolders(myItem.FullName)
Next
'delete all files in the current folder
For Each myItem As FileInfo In strFiles
myItem.Delete()
Next
' delete the starting folder
myfolder.Delete()
End Sub
It's an excellent example of when recursive calls can be used. It's not tested code,and needs to be tested and tweaked for read-only and system files, but the basic design should work.
Enter your message below
Sign in or Join us (it's free).