note 30540 added to function.rmdir
| From: | info at kiwi-interactive dot com | Date: | Fri, 21 Mar 2003 08:58:25 +0000 |
| Subject: | note 30540 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45603@lists.php.net to get a copy of this message | ||
Struggling to get the above functions to remove folder upon folder?
Try this
------------------------
function delete_file($dir){
$dh=opendir($dir);
while ($file=readdir($dh)){
echo("file:".$file."<br />");
if($file!="." && $file!=".."){
$fullpath=$dir."/".$file;
echo("fullpath: ".$fullpath."<br />");
if(!is_dir($fullpath)){
unlink($fullpath);
else{
$subdir=delete_file($fullpath);
if(!$subdir) {
rmdir($fullpath);
}
}
}
}
closedir($dh);
if(rmdir($dir)){
return true;
}else{
return false;
}
}
-------------------------
This will open a directory, examine the contents, and remove any files. IF it finds a folder inside,
it will open it and remove files, and if it finds another folder it will ... you get the picture
--
http://www.php.net/manual/en/function.rmdir.php
http://master.php.net/manage/user-notes.php?action=edit+30540
http://master.php.net/manage/user-notes.php?action=delete+30540
http://master.php.net/manage/user-notes.php?action=reject+30540