Solved

Need code to delete folder, files, and subfolders

Posted on 2007-04-05
2
1,445 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:PBLack
2 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 18857258
       If source.Exists Then
            source.Delete(true)
        End If
0
 

Author Comment

by:PBLack
ID: 18858748
Thank you.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now