Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-12-2002, 06:24 PM   PM User | #1
IKinsler
New Coder

 
Join Date: Jul 2002
Location: Regina, Saskatchewan, Canada
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
IKinsler is an unknown quantity at this point
unlink()?

How do you delete a directory?

I have always used unlink() to delete files, and just the other day tried to delete a directory with it. This is what I put:

unlink("./folder/");

Is there a reason that doesnt work? Do I need an extra parameter if it is for a directory?

Thanks in advance!
__________________
Jared Brandt
IKinsler
IKinsler is offline   Reply With Quote
Old 07-12-2002, 07:38 PM   PM User | #2
Feyd
Regular Coder


 
Feyd's Avatar
 
Join Date: May 2002
Location: Los Angeles, CA Maxim: Subvert Society
Posts: 404
Thanks: 0
Thanked 0 Times in 0 Posts
Feyd is an unknown quantity at this point
Try rmdir

More info : http://www.php.net/manual/en/function.rmdir.php
__________________
Moderator, Perl/CGI Forum
shadowstorm.net - subvert society
Feyd is offline   Reply With Quote
Old 07-12-2002, 07:41 PM   PM User | #3
Flamerule
New Coder

 
Join Date: Jun 2002
Location: Paris, France
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Flamerule is an unknown quantity at this point
Are you sure the dir dosn't have any files in it? If so it won't work : you need to delete them first.
__________________
I don't suffer from insanity, I enjoy every single minute of it!
Flamerule is offline   Reply With Quote
Old 07-12-2002, 07:47 PM   PM User | #4
IKinsler
New Coder

 
Join Date: Jul 2002
Location: Regina, Saskatchewan, Canada
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
IKinsler is an unknown quantity at this point
OH! Well that's my problem then! I've still got files! I will try deleting them and THEN rmdir().

Thanks to both of you!
__________________
Jared Brandt
IKinsler
IKinsler is offline   Reply With Quote
Old 07-12-2002, 07:48 PM   PM User | #5
Feyd
Regular Coder


 
Feyd's Avatar
 
Join Date: May 2002
Location: Los Angeles, CA Maxim: Subvert Society
Posts: 404
Thanks: 0
Thanked 0 Times in 0 Posts
Feyd is an unknown quantity at this point
Here's a function somebody came up with a while ago that will clean the files in the dir and them remove the dir...

PHP Code:
<?php
function delete($file) {
 
chmod($file,0777);
 if (
is_dir($file)) {
  
$handle opendir($file); 
  while(
$filename readdir($handle)) {
   if (
$filename != "." && $filename != "..")
{
    
delete($file."/".$filename);
   }
  }
  
closedir($handle);
  
rmdir($file);
 } else {
  
unlink($file);
 }
}
delete("ordnername");
?>
__________________
Moderator, Perl/CGI Forum
shadowstorm.net - subvert society
Feyd is offline   Reply With Quote
Old 07-12-2002, 09:28 PM   PM User | #6
IKinsler
New Coder

 
Join Date: Jul 2002
Location: Regina, Saskatchewan, Canada
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
IKinsler is an unknown quantity at this point
Thanks, Feyd!

I had that figured out, but unfortunately that doesn't work either! You see, I have no idea how many directories are in the directory I wish to delete - it could be 10 or 20! I had a function that would delete it if it was a file, and empty it and then delete it if it was a dir. But, apparently you cannot launch a function if you're already in it! So that didn't work either.
__________________
Jared Brandt
IKinsler
IKinsler is offline   Reply With Quote
Old 07-13-2002, 07:10 AM   PM User | #7
Flamerule
New Coder

 
Join Date: Jun 2002
Location: Paris, France
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Flamerule is an unknown quantity at this point
How about having two functions :

One that does the cleaning
One that calls the one that does the cleaning.

The the first function goes upon another dir it calls the second function which calls the first.....

Should work.....
__________________
I don't suffer from insanity, I enjoy every single minute of it!
Flamerule is offline   Reply With Quote
Old 07-13-2002, 10:04 AM   PM User | #8
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,891
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
not for the feint-hearted...

exec('rm -f -R /get/this/path/right/directory');

but be sure to get the path right else tears will be forthcoming & dont blame me.
note some hosts disallow exec() calls.
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:13 AM.


Advertisement
Log in to turn off these ads.