Recursive delete of directory - Directory not empty error

G

Gordon

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.
 
N

nolo contendere

Gordon said:
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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top