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);} ‐‐’'''' .$a) && ($a!='.') && ($a!='..')) $a))//Is it empty? >} If (IS_EMPTY_DIR ($ PATHDIR. '/'. $ A)) {// If it is empty, delete rmdir ($ PATHDIR. '/'. $ A); } } } $ d-& gt; close (); Echo "must first delete all files in the directory"; // } } function is_empty_dir($pathdir) { //Judge whether the directory is empty, isn’t my method very good? Just see if there are other things besides . and .. that are not empty $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/327525.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327525.htmlTechArticle1. The recursive copy code is as follows: deleteDir($dir) { if (rmdir($dir)== false is_dir($dir)) { if ($dp = opendir($dir)) { while (($file=readdir($dp)) != false) { if (is_dir($fil...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn