Solved

DirectoryInfo Error / Getting all directories in a given path

Posted on 2006-07-19
2
233 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
[X]
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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 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