note 119321 deleted from function.rmdir by cmb
| From: | cmb@php.net | Date: | Thu, 12 May 2016 17:30:54 +0000 |
| Subject: | note 119321 deleted from function.rmdir by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-205474@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
<?php
//This is one example to delete full directory with all files inside there
function delDir($path){
if(is_dir($path) == TRUE){
$rootFolder = scandir($path);
if(sizeof($rootFolder) > 2){
foreach($rootFolder as $folder){
if($folder != "." && $folder != ".."){
//Pass the subfolder to function
delDir($path."/".$folder);
}
}
//On the end of foreach the directory will be cleaned, and you will can use rmdir, to remove it
rmdir($path);
}
}else{
if(file_exists($path) == TRUE){
unlink($path);
}
}
}
?>