C# DirectoryInfo.MoveTo for Renaming Sometimes throws IOException
<p>I am trying to use DirectoryInfo.MoveTo() to rename a directory that I have just extracted a Zip archive to.  Most of the time the operation throws an IOException with the error <code>Access to the path '...' is denied.</code>.  Occasionally, the operation works, but I haven't been able to correlate any condition that supports this.  I've checked many forum posts and StackOverflow questions about this same error but I still cannot get this working.  I'm sure its not computer permissions.  All of these files and folders have full read/write permissions and I have tried running the program as an administrator.</p>

<p>Here is my code:</p>

<pre><code>// Compute directory names
string directoryPathWithPrefix = Path.Combine(this.OutputDirectory.FullName,
    "TEMP_ " + Path.GetFileNameWithoutExtension(compressedData.FullName));

string directoryPathWithoutPrefix = Path.Combine(this.OutputDirectory.FullName,
    Path.GetFileNameWithoutExtension(compressedData.FullName));

// Extract file to new directory
ZipFile.ExtractToDirectory(compressedData.FullName, directoryPathWithPrefix);

// Add tag for UploadId
File.Create(Path.Combine(directoryPathWithPrefix,
    upload.UploadId.ToString() + ".UPLOADID")).Close();

// Rename file
DirectoryInfo oldDir = new DirectoryInfo(directoryPathWithPrefix);
oldDir.MoveTo(directoryPathWithoutPrefix);
</code></pre>

<p>I've tried using Process Explorer to monitor the handle for the directory, but haven't been able to find any useful data from it. Using Directory.Move() or creating a ZipArchive object inside a <code>using</code> block still raise the error as well.</p>

<p>I'm really stumped on this one. Please help.</p>

<p><strong>Clarification:</strong>
I'm running Windows 7 and this program is built under .NET 4.5</p>

<p>Here is the error I am receiving:</p>

<pre><code>System.IO.IOException occurred
  HResult=-2146232800
  Message=Access to the path '{PATH}' is denied.
  Source=mscorlib
  StackTrace:
       at System.IO.DirectoryInfo.MoveTo(String destDirName)
       at DataImporter.ImportFDUU(FileSystemInfo uploadToImport, Message&amp; reportMessage) in {CODE FILE}:line 380
  InnerException: 
</code></pre>

<p>Running cacls on the directory returns this information:</p>

<pre><code>            BUILTIN\Administrators:(OI)(CI)F

            {MY USER}:(OI)(CI)F
</code></pre>