Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1104639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:30:42+00:00 2026-05-17T01:30:42+00:00

I recently came across a problem with My.Computer.FileSystem.DeleteDirectory() . It will not delete read

  • 0

I recently came across a problem with My.Computer.FileSystem.DeleteDirectory(). It will not delete read only files.

I found out by Googling that I could delete the read only files by changing the file attributes to ‘Normal’. So I wrote a recursive function, as below.

Private Sub DeleteDir(ByVal dir As DirectoryInfo)

    For Each d In dir.GetDirectories
        DeleteDir(d)
    Next
    For Each f In dir.GetFiles
        Try
            f.Attributes = FileAttributes.Normal
            f.Delete()
        Catch ex As Exception
            Log(ex.Message)
        End Try
    Next
    dir.Delete(True)
End Sub

It seems to work fine, but it would be nice if My.Computer.FileSystem.DeleteDirectory() had another parameter to delete read only files, or there was an easier way to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:30:43+00:00Added an answer on May 17, 2026 at 1:30 am

    My understanding is that the classes in the My namespace are partly meant as a crutch to new developers (possibly with a VB6 background) that finds the .Net framework a bit overwhelming. If they made the My namespace too big, I think it would defeat that purpose of being easier to find things in. I would also assume that they probably had limited resources to build that namespace and had to be quite selective.

    The solution is for you to do as you’ve done and write your own method, which you could then put in a class library or similar together with other helpful helper functions that you can then easily include in all your projects.

    Btw, remember that dir.Delete(True) can throw exceptions as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently came across an IE7 only bug that I thought I'd share so
I recently came across a ASP 1.1 web application that put a whole heap
I recently came across this in some code - basically someone trying to create
I recently came across the data structure known as a skip list . It
I was working on some code recently and came across a method that had
I was reading some Java recently and came across something (an idiom?) new to
An interesting issue came up recently. We came across some code that is using
I came across this recently, up until now I have been happily overriding the
I came across a reference to it recently on proggit and (as of now)
I recently started to learn about LINQ and came across the OrderBy extension method.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.