Reputation: 1063
I want to delete all files and folders inside one folder.
If Not Directory.Exists(txtTXT.Text) Then
Return
End If
Dim files() As String
files = Directory.GetFileSystemEntries(txtTXT.Text)
For Each element As String In files
If (Not Directory.Exists(element)) Then
File.Delete(Path.Combine(txtTXT.Text, Path.GetFileName(element)))
End If
Next
My code only deletes the files, but not the folders... How can I delete all?
Upvotes: 1
Views: 10003
Reputation: 1063
I revised my program, so I used this code..
My.Computer.FileSystem.DeleteDirectory( _
My.Computer.FileSystem.SpecialDirectories.Desktop + "\epubcount", _
FileIO.DeleteDirectoryOption.DeleteAllContents)
Upvotes: 2
Reputation: 63471
Turn this code into a function. Make a recursive call to the function when you encounter a directory, passing the directory name to it. The function should also delete the directory that was passed in.
Upvotes: 0