Delete Folders and Containing Files

lab12 picture lab12 · Feb 11, 2010 · Viewed 75.5k times · Source

I have a really quick question. My program actually downloads a zip file then extracts it onto their desktop. But I need an uninstall feature for it, which is basically deleting multiple folders and containing files. How can I do this in vb.net?

Answer

Steve Danner picture Steve Danner · Feb 11, 2010

If all of your folders are contained in a single folder, it should be pretty straight forward.

Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\YOURPATH"
System.IO.Directory.Delete(path, True)

That will delete your root directory, and all the directories and files below it. You could just call this several times over if your files and directories are not all in a single root directory like "YOURPATH" in the example. This will spare you from having to remove each file individually.