Link to home
Start Free TrialLog in
Avatar of Todd MacPherson
Todd MacPhersonFlag for Canada

asked on

Need code to delete folder, files, and subfolders

Hi

USING VB.NET 2003

I am trying to write some code to delete the main folder and all of its contents - files and subfolders sub-subfolders etc.

I have

        'delete all user created tab folders and their contents
        Dim SourceDir As String = Application.StartupPath & "\Projects\" & clsGlobals.Form2.lblProjName.Text & "\Tabs" & "\" & TabControl1.SelectedTab.Text & ""
        Dim source As DirectoryInfo = New DirectoryInfo(SourceDir)

        If source.Exists Then
            source.Delete()
        End If

Thinking that it would do the trick but it crashes because the folder is not empty. So How do I get it to drill down through the main folder and wipe everything out? Have tinkered a bit but got nowhere.

Thanks

PBLack
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Todd MacPherson

ASKER

Thank you.