473,549 Members | 2,247 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 2389
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...@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>
Jun 27 '08 #3

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

Similar topics

5
20085
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
3694
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 Directory.GetFileSystemEntries(path), but I would like to know how to put this together, knowing which entry is a Subdirectory and which entry is a...
9
8312
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) and two folders (Subfolder 1, Subfolder 2). .......I need to delete File1, File2, File3. Subfolder 1 contains FileA. .......Need to delete FileA....
5
2888
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 but when it tries to zip one of the directories it fails with the following error: "IOError: Permission denied: 'c:\\aaa\\temp'" The script I...
24
7523
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 the folder but I get the error message when the procedure attempts to delete the folder selected in the BrowseforFolderbyPath function. How can I...
10
2541
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 search....would any of you be so kind to explain it to me...maybe include some examples. I would GREATLY appreciate it!!!
2
3004
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 the iterator of os.walk chokes. OK that is somehow clear to me as it can't be valid anymore since it can't go to the just deleted directory but it is...
5
33138
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 f.Delete() --error "the directory is not empty" End If How can I delete a folder with files underneath it ? Thank you.
5
3538
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. 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...
3
4221
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 reference, which means it is only collected by the mark-and-sweep collector, not by reference counting. Here is some code that demonstrates it: ===...
0
7472
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7986
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7832
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6074
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5391
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5114
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1083
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
786
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.