PHP function 'scandir' shows deleted directory when deleted directory was open in Windows Explorer
<p>I am running Apache HTTP server 2.4 on a Windows Server 2008 R2 machine with PHP 5.4.4.</p>

<p>I have the following directory structure on my <code>E:\</code> drive:</p>

<pre><code>E:\Dir1\Dir2\Dir3
</code></pre>

<p>All of the directories (<code>Dir1</code>, <code>Dir2</code> and <code>Dir3</code>) are empty (they have no files) except for the child directories shown above.</p>

<p>I am trying to delete <code>Dir3</code> and then look at the contents of directory <code>Dir2</code> to make sure that there's nothing there.  I have written the following PHP script to test this:</p>

<pre><code>&lt;?php

    $currentDir = "E:\\Dir1\\Dir2\\Dir3";

    $parentDir = dirname( $currentDir );  // Get the parent directory for Dir3.

    rmdir ( $currentDir );  // Remove directory Dir3.

    echo "&lt;b&gt;Current directory:&lt;/b&gt; " . $currentDir . " &lt;b&gt;&lt;&lt; I don't exist, I was just deleted.&lt;/b&gt;&lt;br /&gt;";
    echo "&lt;b&gt;Parent directory:&lt;/b&gt; " . $parentDir. "&lt;br /&gt;";

    echo "&lt;b&gt;According to 'scandir', the parent directory contains:&lt;/b&gt; ";
    print_r( scandir( $parentDir, SCANDIR_SORT_NONE ) );
    echo "&lt;br /&gt;&lt;br /&gt;";

?&gt;
</code></pre>

<p>If I do <strong>not</strong> have <code>Dir3</code> open in Windows Explorer, the script above woks perfectly and delivers the following output:</p>

<blockquote>
  <p><strong>Current directory:</strong> E:\Dir1\Dir2\Dir3 <strong>&lt;&lt; I don't exist, I was just deleted.</strong></p>
  
  <p><strong>Parent directory:</strong> E:\Dir1\Dir2</p>
  
  <p><strong>According to 'scandir', the parent directory contains:</strong> Array ( [0] => . [1] => .. ) </p>
</blockquote>

<p>However, if I have <code>Dir3</code> open in Windows Explorer, I get the following output:</p>

<blockquote>
  <p><strong>Current directory:</strong> E:\Dir1\Dir2\Dir3 <strong>&lt;&lt; I don't exist, I was just deleted.</strong></p>
  
  <p><strong>Parent directory:</strong> E:\Dir1\Dir2</p>
  
  <p><strong>According to 'scandir', the parent directory contents:</strong> Array ( [0] => . [1] => .. [2] => Dir3 ) </p>
</blockquote>

<p>Notice that <code>Dir3</code> appears in the array of contents for <code>Dir2</code>.  In other words, <code>scandir()</code> thinks that <code>Dir3</code> still exists even when I know for a fact that it doesn't (Windows explorer kicks me back to <code>Dir2</code>).</p>

<p>Does anyone know why this is happening?</p>
