473,509 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
Jun 27 '08 #1
2 2385
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
Jun 27 '08 #2
On Apr 14, 1:00*pm, Thomas 'PointedEars' Lahn <PointedE...@web.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>
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
20075
by: betterdie | last post by:
Dear guru I want to delete all file and folder recursivly under php code, can anyone give me commend for this. Thank very much
4
3688
by: Elmo Watson | last post by:
Is there a way, with the System.IO class, to do a recursive list of a directory structure? For instance, in DirectoryInfo, you have GetDirectories and GetFiles .... In Directory, you have...
9
8307
by: Paul | last post by:
I'm trying to make get my app to delete all the files in a specified folder and all the files within the folders of the specified folder. e.g. Folder 1 contains three files (File1, File2, File3)...
5
2881
by: Jandre | last post by:
Hi I am a python novice and I am trying to write a python script (most of the code is borrowed) to Zip a directory containing some other directories and files. The script zips all the files fine...
24
7513
by: biganthony via AccessMonster.com | last post by:
Hi, I have the following code to select a folder and then delete it. I keep getting a Path/File error on the line that deletes the actual folder. The line before that line deletes the files in...
10
2538
by: AsheeG87 | last post by:
Hello Everyone! I have a linked list and am trying to include a recursive search. However, I am having trouble understanding how I would go about that. I don't quite understand a recursive...
2
3000
by: Martin Marcher | last post by:
Hello, I'm playing around with os.walk and I made up del_tree(path) which I think is correct (in terms of the algorithm, but not as python wants it :)). As soon as some directory is deleted...
5
33126
by: fniles | last post by:
I am using VB.NET 2005. When I try to delete a folder that has files underneath it, it gave me "the directory is not empty" error. f = New IO.DirectoryInfo("C:\myfolder") If f.Exists Then...
5
3533
by: Gordon | last post by:
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. ...
3
4216
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular...
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.