Solved

DirectoryInfo Error / Getting all directories in a given path

Posted on 2006-07-19
2
229 Views
Last Modified: 2010-04-23
I'm using the following code which appears as if it should get all the directories on my hard drive (or any given path).  The problem is, even as an admin of my machine there are protected directories that I apparantly don't have access too and it throws an access exception on the for each line (The specific error is:  Access to the path 'c:\WINDOWS\Cannot delete for whatever reason\8fae693e482ad5d9c6a7b4e423dcd452\sp1' is denied.).  Is there an obvious solution I'm missing without writing more code to recurse manually?

I'm less concerned with the fact that I don't have access to certain directories, that will happen in how I'm going to use this anyway.  I'd prefer it just skipped those directories and moved on (the GetDirectories halts though on this exception).

        Dim rootDi As New DirectoryInfo("c:\")

        For Each di As DirectoryInfo In rootDi.GetDirectories("*", SearchOption.AllDirectories)
            Label1.Text = di.FullName
            Application.DoEvents()
        Next
0
Comment
Question by:IUFITS
2 Comments
 
LVL 11

Accepted Solution

by:
LordWabbit earned 500 total points
ID: 17144943
Nope some folders are off limits, your best option would be to do some manual recursion like

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        GetDirectories("C:\")
    End Sub

    Private Sub GetDirectories(ByVal Path As String)
        Try
            Dim arrDir() As String = System.IO.Directory.GetDirectories(Path)
            For Each eleDir As String In arrDir
                ListBox1.Items.Add(eleDir)
                Application.DoEvents()
                GetDirectories(eleDir)
            Next
        Catch ex As Exception

        End Try
    End Sub
0
 
LVL 3

Author Comment

by:IUFITS
ID: 17146825
That appears to do the trick since it errors out on just directories it can't read.  Thanks for a quick and correct response.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2013 Shortcut (VB) 4 45
vb.net checkbox 7 46
scanning dentists xray (the small ones) 3 53
Vb. Net application freezes 9 45
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

16 Experts available now in Live!

Get 1:1 Help Now