Need code to delete folder, files, and subfolders

Posted on 2007-04-05
Last Modified: 2008-01-09


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


Question by:PBLack
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 48

Accepted Solution

AlexFM earned 500 total points
ID: 18857258
       If source.Exists Then
        End If

Author Comment

ID: 18858748
Thank you.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL ( and MongoDB (…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question