vb.netvisual-studio-2010directorydelete-file

Delete Folders and Containing Files


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?


Solution

  • 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.