title: System.UnauthorizedAccessException when getting files
body: <p>I've asked a very similar question before <a href="https://stackoverflow.com/questions/20544211/system-unauthorizedaccessexception-when-getting-directories">here</a>. But that was about getting directories, and this is about files. And these codes are a bit different from each other. Ever since I've been trying to convert this to make it look like the <a href="https://stackoverflow.com/a/20545860/3095385">answer</a> on my old question, I haven't been able to make it work.</p>
  
  <pre><code>string[] files = Directory.GetFiles(ScanPath, "*.*", System.IO.SearchOption.AllDirectories);
  DateTime From = DateTime.Now.AddHours(-24);
  DateTime To = DateTime.Now;
  
  foreach (string name in files)
  {
     FileInfo file = new FileInfo(name);
     string fullname = file.FullName;
  
     if (file.LastWriteTime &gt;= From &amp; file.LastWriteTime &lt;= To &amp;&amp; file.Length &gt;= ScanSize)
        Console.WriteLine(file.FullName + " ; " + "last changed at  " + " ; " + file.LastWriteTime.ToString());
  }
  </code></pre>
  
  <p>I've been getting the same errors as I explained in the other question. Because I don't know where to put the code of the <code>foreach</code> in a recursion. Since it's not an enumeration but a <code>Directory.GetFiles()</code>.</p>
  
  <p>The error occurs with:</p>
  
  <p><code>Directory.GetFiles(ScanPath, "*", SearchOption.AllDirectories);</code></p>
  
  <p>because this gets all the files of the directories at once. But if I remove it, it only gets the files in the given path, without any of the files in the subdirectories. So I was told to apply recursion.</p>
  
  <p>I am the administrator of the system and I plan to run this on the entire data drive. D:\</p>
  
  <p>I'm hoping anyone here knows a good example.</p>