title: Check if directory is accessible in C#?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2336699/net-check-if-directory-is-accessible-without-exception-handling">.NET - Check if directory is accessible without exception handling</a>  </p>
  </blockquote>
  
  
  
  <p>Im making a small file explorer in Visual Studio 2010 with NET 3.5 and C#, and I have this function to check if a directory is accessible:</p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <p>But I think with big directories it could be slow trying to get all sub directories to check if directory is accesible. 
  Im using this function to prevent errors when trying to explore protected folders or cd/dvd drives without disc ("Device Not Ready" error).</p>
  
  <p>Is there a better way (faster) to check if directory is accessible by the application (preferably in NET 3.5)?</p>