Yesterday I saw a post (chinaasp) asking how to delete a directory. It has always been possible before, but something went wrong yesterday. It turned out that he just deleted the files at the lower level and then deleted the
directory. So if there are a few more levels, there will be question.
I can only make do with this temporarily. If your directory does not have more than ten levels, it should be fine~, but I am not familiar with recursion and can only do
deltree($ path);rmdir($path) to delete this directory. Is it possible to delete this directory directly with deltree($path);? ?
function deltree($pathdir)
{
echo $pathdir;//I use it when debugging
if(is_empty_dir($pathdir))//If it is empty
{
rmdir($pathdir);//Delete directly
}
else
{//Otherwise read this directory, except . and ..
$d=dir( $pathdir);
while($a=$d->read())
{
if(is_file($pathdir.'/'.$a) && ($a!='. ') && ($a!='..')){unlink($pathdir.'/'.$a);}
// If it is a file, delete it directly
'/'.$a) && ($a!='.') && ($a!='..'))
/<..> {// If not, call itself, but it is the original path+his subordinates' directory name
Deltree ($ Pathdir. '/'. $ a) ;
;
}
}
function is_empty_dir($pathdir)
{//My method of judging whether the directory is empty is not very good, right? Just to see if there are other things besides . and .. that are not empty, does PHP provide any
function?
$d=opendir($pathdir);
$i=0;
while($a=readdir($d))
{
$i++;
}
closedir($d);
if($i>2){return false;}
else return true;
}
http://www.bkjia.com/PHPjc/316344.html
www.bkjia.com
true