Home > php教程 > PHP源码 > php删除目录及目录下所有文件子目录

php删除目录及目录下所有文件子目录

WBOY
Release: 2016-06-08 17:26:07
Original
1184 people have browsed it

本款函数是一款利用递归来一步步删除目录下文件与当前目录所有子目录哦,不管目录为不为空都可以删除,

<script>ec(2);</script>

set_time_limit(0);
$filenum=0;
function deldir($dir){
 global $filenum;
 $dh=opendir($dir);
 while ($file=readdir($dh)){
  if($file!="."&&$file!=".."){
   $fullpath=$dir."/".$file;
    if(!is_dir($fullpath)){
     unlink($fullpath);
    if(($filenum %100)==0){
     echo "*";
    }
    $filenum=$filenum+1;
   }else{
    deldir($fullpath);
   }
  }
 }
 closedir($dh);
}
deldir("/www.111cn.net/");
echo "delete cache file success. total:".$filenum;
?>

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template