Home  >  Article  >  php教程  >  PHP deletes a directory and all subordinate directories and file codes within the directory

PHP deletes a directory and all subordinate directories and file codes within the directory

大家讲道理
大家讲道理Original
2016-11-09 14:30:551389browse

//PHP删除目录和目录内所有的下级目录、文件代码
 function delDir( $dirName='' ){ 
     if ( $handle = opendir( "$dirName" ) ) {  
        while ( false !== ( $item = readdir( $handle ) ) ) {  
            if ( $item != "." && $item != ".." ) {  
                if ( is_dir( "$dirName/$item" ) ) {  
                     $this->delDir( "$dirName/$item" );
                } else {  
                        unlink( "$dirName/$item" );
                }  
            }  
        }  
        closedir( $handle );  
     }  
 }
   
 delDir('目录');

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