note 31279 added to function.rmdir
| From: | konik at rack1 dot php dot net | Date: | Wed, 16 Apr 2003 08:29:04 +0000 |
| Subject: | note 31279 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46673@lists.php.net to get a copy of this message | ||
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;
}
}
}
--
http://www.php.net/manual/en/function.rmdir.php
http://master.php.net/manage/user-notes.php?action=edit+31279
http://master.php.net/manage/user-notes.php?action=delete+31279
http://master.php.net/manage/user-notes.php?action=reject+31279