Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone.....

I want to search all sub directory within a directory
my code is
C#
DirectoryInfo di = new DirectoryInfo(Search_Path);
DirectoryInfo[] direcorries = di.GetDirectories("*.*", SearchOption.AllDirectories);


but here i got an exception

C#
exception {"Access to the path 'F:\\System Volume Information\\' is denied."}	System.Exception {System.UnauthorizedAccessException}


but if i used

C#
DirectoryInfo di = new DirectoryInfo(dir);
DirectoryInfo[] direcorries = di.GetDirectories("*.*", SearchOption.TopDirectoryOnly);

then it does not through an exception ....

why this happens?

I want to avoid this System Volume Information folder. How can i do that ??
Posted
Updated 13-Sep-12 22:34pm
v2

1 solution

AFAIK, it would be difficult to skip them through code using any direct option. I looked for something similar if already discussed earlier and found this answer by SA: How to display accessible files only and skip inaccessible file?[^]

It looks like, you don't have a direct way to go through all skipping inaccessible folders by any setting. You need to handle those specific errors in a try-catch and move on. Not a good way but looks like the possible way to get you seek.
 
Share this answer
 
Comments
krushna chandra jena 14-Sep-12 4:46am    
Thanks for suggestion ....
Sandeep Mewara 14-Sep-12 9:06am    
Welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900