php 递归删除目录

.is_file:判断是否是文件

is_dir:判断是否为目录

file_exists  = is_file + is_dir   判断是文件或目录 

function delDir($dirPath) {

  $dir = opendir($dirPath);

  while ($file = readdir($dir)) {

    if ($file == '.' || $file == '..') {

      continue ; 

    }

    $filePath = $dirPath.'/'.$file;

    if (is_file($filePath)) {

      unlink($filePath);

    } else {

      delDir($dirPath);

    }

  }

  rmdir($dirPath);

  closedir($dir);

}

posted @ 2017-09-18 10:52  夜啸苍姬  阅读(58)  评论(0编辑  收藏  举报