DirectoryInfo Error / Getting all directories in a given path
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
Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.