Home > php教程 > PHP源码 > A class encapsulated in PHP to display/delete all files and empty directories in the file directory. At the same time, the directory or directory and file with the file name 0 can be deleted.

A class encapsulated in PHP to display/delete all files and empty directories in the file directory. At the same time, the directory or directory and file with the file name 0 can be deleted.

大家讲道理
Release: 2016-11-08 11:48:08
Original
1189 people have browsed it

<?php
class file{
    static public function ShowDir($path,$level=0){
        $dir=opendir($path);
        while(($file=readdir($dir)) !==false){
            if($file!=&#39;.&#39; && $file!=&#39;..&#39;){
                $filepath=$path.&#39;/&#39;.$file;
                for($i=0;$i<$level*5;$i++){
                    echo " ";
                }
                echo $file.&#39;<br>&#39;;
                if(is_dir($filepath)) {
                static::ShowDir($filepath, $level + 1);
                }
            }
        }
        closedir($dir);
    }
    static public function DeleteDir($path){
        $dir=opendir($path);
        while(($file=readdir($dir)) !== false){
            if($file!=&#39;.&#39; && $file!=&#39;..&#39;){
                $filepath=$path.&#39;/&#39;.$file;
                if(is_dir($filepath)){
                    self::DeleteDir($filepath);
                }else{
                    unlink($filepath);
                }
            }
        }
        closedir($dir);
        rmdir($path);
    }
}
?>
Copy after login

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