kelvzy
kelvzy

Reputation: 1063

Delete all files and folder

I want to delete all files and folders inside one folder.

Code

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

Answers (2)

kelvzy
kelvzy

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

paddy
paddy

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

Related Questions