Delete directory returns access to the path is denied
<p>I have code that looks for empty directories that are older than 1 hour and deletes them</p>

<pre><code>foreach (DirectoryInfo __dir in _directories)
{
    if (!__dir.EnumerateFiles().Any() &amp;&amp; __dir.LastWriteTime &lt; DateTime.Now.AddHours(-1))
    {
        Directory.Delete(__dir.FullName)
    }
}
</code></pre>

<p>That throws an exception saying access to the directory path is denied. However I'm able to manually delete the same directory through file explorer.<br> 
I tried what other people suggested (setting attributes to normal), but that didn't work.</p>

<p>I tried <code>FileAttributes.Normal;</code> and <code>~FileAttributes.ReadOnly;</code> Neither of them work.
<br>
I also tried setting access control to full control of the directory I'm trying to delete as well as it's parent directories.</p>