title: Directory.Delete runs into IOException
body: <p>I have created a shell script in C# that deletes Windows home folders on the server. The home folders are given by a text-file. The script loops thru the folders and deletes them. I have two log files a "success"-log and a "error"-log.</p>
  
  <p>The deleting part looks like:</p>
  
  <pre><code>if (Directory.Exists(serverShare + "\\" + user))
  {
         try
         {
                 Directory.Delete(serverShare + "\\" + user, true);
                 successLog.WriteLine(serverShare + "\\" + user + " --- deleted");
         }
         catch (Exception ex)
         {
                 errorLog.WriteLine(serverShare + "\\" + user + " --- Error: {0}", ex.ToString());
         }
  }
  else
  {
        errorLog.WriteLine(serverShare + "\\" + user + " -- Errror: Directory not exists!");
  }
  </code></pre>
  
  <p>Now I run into an exception: </p>
  
  <blockquote>
    <p>"System.IO.IOException: The process cannot access the file because it
    is being used by another process. directory.delete pictures
    documents".</p>
  </blockquote>
  
  <p>The folder was not in use (the users who access it, works no longer in the company), so no another process can access it.</p>
  
  <p>The exception occurs with folders <code>my documents\my music</code>, <code>my documents\my pictures</code>. So it could be do something with special Windows folders?</p>
  
  <p>The other folders are deleted. So the script "works". Also no problems in local environment.</p>