Recursive delete of directory - Directory not empty error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gordon

    Recursive delete of directory - Directory not empty error

    I'm trying to remove a directory and all its contents from within a
    script. I wrote a recursive function to take care of it, but when I
    run it I get random "Directory not empty" error messages.

    I dropped some code in to echo out the name of the file that's about
    to be rmdir()ed or unoink()ed (depending if it's a file or a
    directory) to see if it was choking on a particular subdirectory, but
    doing that causes all the error messages to stop appearing!

    It looks to me as if at some stages of the script the delete commands
    are being issued too rapidly and the result is that an attempt to
    delete a parent is made before its children have all been deleted.
    The code I added to echo out the directory name first probably
    introduces just enough of a delay for this problem to go away.

    Obviously just doing something in the function to cause a delay isn't
    a good solution, is there a better way of handling this problem?

    I'm running PHP 5 on a Windows development machine through Apache.
    Directory listings are being retrieved from a database.
  • Thomas 'PointedEars' Lahn

    #2
    Re: Recursive delete of directory - Directory not empty error

    Gordon wrote:
    I'm trying to remove a directory and all its contents from within a
    script
    Client-side? Server-side? Is that script even written in an ECMAScript
    implementation? If yes, which one (i.e., which runtime environment)?
    [PHP talk]
    I'm running PHP 5 on a Windows development machine through Apache.
    Directory listings are being retrieved from a database.
    Even if you triggered a server-side PHP script with client-side
    ECMAScript-based scripting, that script would be on-topic in comp.lang.php,
    not here. That said, it makes little sense to me to retrieve the directory
    listing from a database instead of from the filesystem where the directories
    reside.


    PointedEars
    --
    Anyone who slaps a 'this page is best viewed with Browser X' label on
    a Web page appears to be yearning for the bad old days, before the Web,
    when you had very little chance of reading a document written on another
    computer, another word processor, or another network. -- Tim Berners-Lee

    Comment

    • nolo contendere

      #3
      Re: Recursive delete of directory - Directory not empty error

      On Apr 14, 1:00 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
      wrote:
      Gordon wrote:
      I'm trying to remove a directory and all its contents from within a
      script
      >
      Client-side?  Server-side?  Is that script even written in an ECMAScript
      implementation?  If yes, which one (i.e., which runtime environment)?
      >
      [PHP talk]
      I'm running PHP 5 on a Windows development machine through Apache.
      Directory listings are being retrieved from a database.
      >
      Even if you triggered a server-side PHP script with client-side
      ECMAScript-based scripting, that script would be on-topic in comp.lang.php,
      not here.  That said, it makes little sense to me to retrieve the directory
      listing from a database instead of from the filesystem where the directories
      reside.
      I agree, it's odd to retrieve directory listings from a database
      instead of the file system, unless for some reason you wanted a record
      of what existed on the file system at a particular time.

      This seems like more of a Unix question. What's wrong with executing
      the following command from the parent directory?

      rm -rf <dir>

      Comment

      Working...