Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8738825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:48:50+00:00 2026-06-13T10:48:50+00:00

I am running Apache HTTP server 2.4 on a Windows Server 2008 R2 machine

  • 0

I am running Apache HTTP server 2.4 on a Windows Server 2008 R2 machine with PHP 5.4.4.

I have the following directory structure on my E:\ drive:

E:\Dir1\Dir2\Dir3

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

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

<?php

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

    $parentDir = dirname( $currentDir );  // Get the parent directory for Dir3.
        
    rmdir ( $currentDir );  // Remove directory Dir3.
    
    echo "<b>Current directory:</b> " . $currentDir . " <b><< I don't exist, I was just deleted.</b><br />";
    echo "<b>Parent directory:</b> " . $parentDir. "<br />";
                
    echo "<b>According to 'scandir', the parent directory contains:</b> ";
    print_r( scandir( $parentDir, SCANDIR_SORT_NONE ) );
    echo "<br /><br />";

?>

If I do not have Dir3 open in Windows Explorer, the script above woks perfectly and delivers the following output:

Current directory: E:\Dir1\Dir2\Dir3 << I don’t exist, I was just deleted.

Parent directory: E:\Dir1\Dir2

According to ‘scandir’, the parent directory contains: Array ( [0] => . [1] => .. )

However, if I have Dir3 open in Windows Explorer, I get the following output:

Current directory: E:\Dir1\Dir2\Dir3 << I don’t exist, I was just deleted.

Parent directory: E:\Dir1\Dir2

According to ‘scandir’, the parent directory contents: Array ( [0] => . [1] => .. [2] => Dir3 )

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

Does anyone know why this is happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:48:51+00:00Added an answer on June 13, 2026 at 10:48 am

    When you have the directory opened in windows explorer. There is an existing handle to the directory in the OS-es memory. Scandir internally fetches details of directory/file existence from the OS. So when the directory is open and you delete it and run a scandir immediately, then windows returns it because there is a "lock" on the directory handle. This handle closes only when you close the directory (or some internal garbage collections happens at the OS level I guess). When the directory is not open in windows explorer none of these edge cases are happening and so everything works like a charm.

    Again one of the behaviors of windows. I think clearstatcache() is an option, but I believe it works only on posix-compliant Os-es and also scandir() is not affected by it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have next SVN repositories structure running Apache 2.2 under Windows Server 2008: http://example.com/svn/
I have my Apache http server running on localhost:80 and restlet server on localhost:8182,
I have a front-end apache server running in a windows server. The system is
I have installed my PHP scripts which runs over Apache server in a Windows
FYI: I'm running Windows Server 2008 R2, with IIS 7.5 and Apache Tomcat 5.5.
I have followed all the instructions here: http://www.tonyspencer.com/2003/10/22/curl-with-php-and-apache-on-windows/ to install & config apache get
I have a client running a WebLogic 11g install on a Windows Server machine
I have a PHP server running on Apache, I get lots of request looks
I have a rails 3 application running on windows and apache server. As I
I'm running wamp on Vista (Apache v2.2.11) and have projects setup such that http://localhost/projectx

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.