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

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

大家讲道理
Release: 2016-11-09 14:30:55
Original
1501 people have browsed it

//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('目录');
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