note 30540 deleted from function.rmdir by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 07 Aug 2004 23:46:38 +0000 |
| Subject: | note 30540 deleted from function.rmdir by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74164@lists.php.net to get a copy of this message | ||
Note Submitter: info@kiwi-interactive.com
----
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