title: File.Delete Access to the path is denied
body: <p>My console application program is creating some runtime files while it is working so what I want to do is delete all of these files on the application startup. I have tried this: </p>
  
  <pre><code>public static void Empty(string targetDir)
  {
      var directory = new DirectoryInfo(targetDir);
      if (!directory.Exists) return;
      foreach (var file in directory.GetFiles()) file.Delete();
      foreach (var subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
  }
  </code></pre>
  
  <p>...just to look for all the files/folders in the given path (which is in a subdirectory in the program execution path) then delete them. However, I get the following exception: </p>
  
  <blockquote>
    <p>Access to the path 'file' is denied.</p>
  </blockquote>
  
  <p>I tried to run the program as administrator with no luck; However, I want a solution that works without using administrator privileges.</p>
  
  <p>Notes :</p>
  
  <ol>
  <li>The file is not running in another application.</li>
  <li>The file is not in a protected folder.</li>
  <li>The file can be deleted manually with no problems and that's why i
  am here.</li>
  </ol>