Saturday, July 4, 2009

Single Statement for Removal of Folders and SubFolders

To Remove Folders and Sub Folders, a simple statement is enough.



Private Sub RemoveDirectory(ByVal sDirPath As String)

'True indicates the removal of sub folders as well
System.IO.Directory.Delete(sDirPath, True)


End Sub







Private Sub RemoveDirectory(ByVal sDirPath As String)

my.Computer.FileSystem.DeleteDirectory(sDirPath,FileIO.DeleteDirectoryOption.DeleteAllContents)

End Sub



Both the above statements will remove the folders and sub folders.


Example:

RemoveDirectory("C:\Temp")

will remove the folder Temp and its Sub Folders.

No comments:

Post a Comment