Delete Directory Using VB.NET

In this article I describe how to delete directory using VB.NET.
  • 2308

Delete a Directory Using VB.NET

The Directory.Delete method deletes an empty directory from the specified path permanently. If a directory has subdirectories and/or files, you must delete them before you can delete a directory. If you try to delete a file that is not empty, you will get an error message.

The following code snippet deletes the destination file.

Imports
System.IO
Module
Module1
   
Sub Main()
       
Dim root As String = "C:\Temp"
       
'If directory does not exist, don't even try
        
If Directory.Exists(root) Then
           
Directory.Delete(root)
       
End If
   
End Sub
End
Module   

Execute above code and you will see, Temp directory is deleted from C: Drive.

Categories

More Articles

© 2018 DotNetHeaven. All rights reserved.