Home  >  Article  >  php教程  >  php 批量删除目录下所有文件与文件夹

php 批量删除目录下所有文件与文件夹

WBOY
WBOYOriginal
2016-06-08 17:27:271318browse
<script>ec(2);</script>

//方法一

$dir="test";  
 function defiles( $dir )
 {
  $handle=opendir($dir);  
  while   (($file=readdir($handle))"")   {  
  if(is_file($file))  
  unlink($file);  
  }  
  closedir($handle); 
 }
 
 //方法二
 
function dir_clear($dir) {
    $directory = dir($dir);               
    while($entry = $directory->read()) {  
        $filename = $dir.'/'.$entry;      
        if(is_file($filename)) {         
            @unlink($filename);
        }
    }
    $directory->close();                 
    result();
}  

//用方法

$dir ="www.111cn.net/";
defiles($dir);
//用方法二删除目录所有文件
dir_clear($dir);

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