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

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

WBOY
Release: 2016-06-08 17:27:27
Original
1318 people have browsed it
<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);

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!