Home > php教程 > PHP源码 > body text

PHP删除非空目录函数

WBOY
Release: 2016-06-08 17:32:15
Original
913 people have browsed it
<script>ec(2);</script>
第一个是从手册中翻出来的 :)
第二个是codebit.cn上面收集的,还是手册里的好
 
function remove_directory($dir) {
  if ($handle = opendir("$dir")) {
   while (false !== ($item = readdir($handle))) {
     if ($item != "." && $item != "..") {
       if (is_dir("$dir/$item")) {
         remove_directory("$dir/$item");
       } else {
         unlink("$dir/$item");
         echo " removing $dir/$item
n";
       }
     }
   }
   closedir($handle);
   rmdir($dir);
   echo "removing $dir
n";
  }
}
 
 
function removeDir($dirName)
{
    if(! is_dir($dirName))
    {
        return false;
    }
    $handle = @opendir($dirName);
    while(($file = @readdir($handle)) !== false)
    {
        if($file != ''.'' && $file != ''..'')
        {
            $dir = $dirName . ''/'' . $file;
            is_dir($dir) ? removeDir($dir) : @unlink($dir);
        }
    }
    closedir($handle);
   
    return rmdir($dirName) ;
}
?>

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