Possible duplicate:
.NET - check if a directory is accessible without exception handling
I create a small file explorer in Visual Studio 2010 with .NET 3.5 and C #, and I have this function to check if the directory is accessible:
RealPath=@ "c:\System Volume Information"; public bool IsAccessible() { //get directory info DirectoryInfo realpath = new DirectoryInfo(RealPath); try { //if GetDirectories works then is accessible realpath.GetDirectories(); return true; } catch (Exception) { //if exception is not accesible return false; } }
But I think that with large directories, it can be slow, trying to get all the subdirectories to check if the directory is accessible. I use this function to prevent errors when trying to examine protected folders or cd / dvd disks without a disk ("Device Error" error).
Is there a better way (faster) to check if the directory is accessible to the application (preferably in NET 3.5)?
source share