Home > Backend Development > PHP Tutorial > php 删除目录下全部文件的代码

php 删除目录下全部文件的代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:18:28
Original
884 people have browsed it

php 删除目录下所有文件的代码
删除目录下的所有文件的php代码

<?php/**删除目录下所有文件*///删除目录下文件方法一    function clean_dir($path)        {            if (!is_dir($path))        {                    if (is_file($path))        {                            unlink($path);                    }                    return;            }            $p=opendir($path);            while ($f=readdir($p))        {                    if ($f=="." || $f=="..") continue;                    clean_dir($path.$f);            }            rmdir($path);            return;    }    //    function delFile($path,$level = 0) {    // $path $file    //删除目录下所有文件实例二    $file = "";    $lev = 0;    $dir = @opendir($path);    while($con = @readdir($dir)) {      if($con != "." && $con != ".." && $con != "") {       $file = $path."/".$con;       if(is_dir($file)) {        $lev = delFile($file,$level++);        @rmdir($file);       } else {        @unlink($file);       }      }    }    for($i=0;$i<$lev;$i++) {      delFile($path,$level);    }    @rmdir($path);    return $level;    }    delFile("./www.jbxue.com");//目录遍历函数    function dirtree($path="./test") {      echo "<dl>";      $d = dir($path);      while(false !== ($v = $d->read())) {        if($v == "."    $v == "..")          continue;        $file = $d->path."/".$v;        echo "<dt>$v";        if(is_dir($file))          dirtree($file);      }      $d->close();      echo "</dl>";    }//调用示例dirtree();?>
Copy after login

Related labels:
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
Latest Issues
access path
From 1970-01-01 08:00:00
0
0
0
Static resource path usage
From 1970-01-01 08:00:00
0
0
0
objective-c - header search path
From 1970-01-01 08:00:00
0
0
0
javascript - vue src path problem
From 1970-01-01 08:00:00
0
0
0
php move_uploaded_file() path parameter usage
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template