递归删除目录

来源:互联网 发布:java调用同类中的方法 编辑:程序博客网 时间:2024/05/20 03:45
<?php

/*
递归删除目录
*/
class delDir{
    static public function del_dir($path){
        //如果不是目录直接返回
        if(!is_dir($path)){
            return null;
        }
        if ($dh = opendir($path)) {
            while (($file = readdir($dh)) !== false) {
                 //echo "filename: $file : filetype: " . filetype($path .'/'. $file) . "\n";
                 if($file=='.' || $file=='..'){
                     continue;
                 }
                 //判断文件是否是目录
                 //如果是目录的话就直接删除
                 if(!is_dir($path .'/'. $file)){
                     unlink($path .'/'. $file);
                 }else{
                     self::del_dir($path .'/'. $file);
                 }
            }
            closedir($dh);
            rmdir($path);
        }
    }
}


delDir::del_dir('./a');

?>
0 0
原创粉丝点击