Home  >  Article  >  Backend Development  >  Delete all folders and subdirectories in a directory with PHP under Linux_PHP tutorial

Delete all folders and subdirectories in a directory with PHP under Linux_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:54:361055browse

 [php] 
function removeDir($dirName)  
 
{  
 
    if(! is_dir($dirName))  
 
    {  
 
   @unlink($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) ;  
 

 
$dirName1="bmz_cache"; 
 
removeDir($dirName1); 
 
 
?> 
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477929.htmlTechArticle[php] ?php function removeDir($dirName) { if(! is_dir($dirName)) { @unlink($dirName); return false; } $handle = @opendir($dirName); while(($file = @readdir($handle)) !== false) { i...
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