note 61392 deleted from function.rmdir by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 04:28:03 +0000 |
| Subject: | note 61392 deleted from function.rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153267@lists.php.net to get a copy of this message | ||
Note Submitter: mn dot yarar at gmail dot com
----
/***********************************
Author : M. Niyazi Yarar
Created : February, 2006
Description : Simply clean files
and removes the directory
If any error occurs or for your suggestions,
please send me e-mail
***********************************/
function ClearDirectory($path){
if($dir_handle = opendir($path)){
while($file = readdir($dir_handle)){
if($file == "." || $file == ".."){
if(!@unlink($path."/".$file)){
continue;
}
}else{
@unlink($path."/".$file);
}
}
closedir($dir_handle);
return true;
// all files deleted
}else{
return false;
// directory doesnt exist
}
}
function RemoveDirectory($path){
if(ClearDirectory($path)){
if(rmdir($path)){
return true;
// directory removed
}else{
return false;
// directory couldnt removed
}
}else{
return false;
// no empty directory
}
}
/***************************************
Example Usage
if(RemoveDirectory("/mysite/images")){
echo 'Uughh! All images gone!';
}else{
echo 'Ohh, well done. I am so lucky';
}
***************************************/