Recursive delete of directory - Directory not empty error

Discussion in 'Javascript' started by Gordon, Apr 14, 2008.

  1. Gordon

    Gordon Guest

    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.
    Gordon, Apr 14, 2008
    #1
    1. Advertising

  2. On Apr 14, 1:00 pm, Thomas 'PointedEars' Lahn <>
    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>
    nolo contendere, Apr 14, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcia Hon

    Check if a directory is empty and empty it

    Marcia Hon, Feb 8, 2004, in forum: C Programming
    Replies:
    8
    Views:
    563
    Dave Thompson
    Feb 14, 2004
  2. n00m
    Replies:
    12
    Views:
    1,101
  3. vamsi
    Replies:
    21
    Views:
    2,046
    Keith Thompson
    Mar 9, 2009
  4. codeboy
    Replies:
    1
    Views:
    1,551
    Juan T. Llibre
    Jun 8, 2009
  5. codeboy
    Replies:
    3
    Views:
    710
    Juan T. Llibre
    Jun 8, 2009
Loading...

Share This Page