Solved

Need code to delete folder, files, and subfolders

Posted on 2007-04-05
2
1,448 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Showdialog 8 29
Protecting vb6 & .Net code Obfuscation 18 95
VB.Net - Oracle BulkCopy from CSV Date Format 7 47
VS.net 2010 11 23
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

12 Experts available now in Live!

Get 1:1 Help Now