So i'm using Directory.GetFiles(folder, "*.jpg", SearchOption.AllDirectories)
. When i try it on the c:\
drive in windows 7, since windows 7 still had c:\documents and settings
(for legacy systems like xp), it's a protected folder. It's only protected because it's not really a folder. It's kind of a dummy folder. So 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 an UnauthorizedAccessException. It doesn't let me past that. What I'm trying to do is have it skip over any folder that it doesn't have permis开发者_如何学Pythonsion to access, but just continue to search, don't get caught up on the catch block, just continue. Any ideas?
I would try one of the two workarounds in this article (click on workarounds tab near the bottom):
http://connect.microsoft.com/VisualStudio/feedback/details/94751/optionally-prevent-directoryinfo-getfiles-from-throwing-unauthorizedaccessexception
精彩评论