note 31279 deleted from function.rmdir by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 07 Aug 2004 23:46:26 +0000 |
| Subject: | note 31279 deleted from function.rmdir by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74163@lists.php.net to get a copy of this message | ||
Note Submitter: konik
----
After fighting a bit with PHP 4.3 under win 2K for recursive deleting of files and directory i
create this function for *NIX and WIN ( using some of the posts found on this site ) Hope it can
help
function rec_delete($p_path)
{
if(false === @is_dir($p_path)){
@unlink($p_path);
clearstatcache();
if (@file_exists($p_path)) {
if(substr_count($p_path,":")){
@system("del ".eregi_replace("/","\\",$p_path));
}else{
@system("rm $p_path");
}
}
clearstatcache();
if (@file_exists($p_path)){
return false;
}else{
return true;
}
}else{
$dh = @opendir($p_path);
while(($file = @readdir($dh)) !==false ){
if($file != "." && $file != ".."){
$fullpath = $p_path.$file;
if(@is_dir($fullpath))$fullpath.="/";
if (!rec_delete($fullpath)){
closedir($dh);
return false;
}
}
}
@closedir($dh);
@rmdir($p_path);
clearstatcache();
if (@file_exists($p_path)) {
if(substr_count($p_path,":")){
@system("del ".eregi_replace("/","\\",$p_path));
}else{
@system("rmdir $p_path");
}
}
clearstatcache();
if (@file_exists($p_path)){
return false;
}else{
return true;
}
}
}