Trying to use Directory.EnumerateFiles ("*. Jpg", SearchOption.AllDirectories);

So, I'm using Directory.GetFiles(folder, "*.jpg", SearchOption.AllDirectories) . When I run it on the c:\ drive in Windows 7, since Windows 7 still has c:\documents and settings (for legacy systems like xp), this is a protected folder. It is protected only because it is not a folder. This is a kind of empty folder. Therefore, when I run this code:

 try { string[] folders = Directory.GetFiles(@"C:\\","*.jpg", SearchOption.AllDirectories); foreach (string item in folders) { //blah blah } catch { } 

It always throws a UnauthorizedAccessException. This does not allow me to get past this. What I'm trying to do is skip any folder in which it does not have permission to access, but just keep searching, don't get to the catch block, just keep going. Any ideas?

+4
source share
1 answer
+2
source

All Articles