zoukankan      html  css  js  c++  java
  • 删除目录及目录文件

    /**
      +-----------------------------------------------------------------------------------------
      * 删除目录及目录下所有文件
      +-----------------------------------------------------------------------------------------
      * @param str $path   待删除目录路径
      +-----------------------------------------------------------------------------------------
      * @param int $deldir 是否删除目录,1或true删除目录,0或false则只删除文件保留目录(包含子目录)
      +-----------------------------------------------------------------------------------------
      * @return bool 返回删除状态
      +-----------------------------------------------------------------------------------------
    */
    function delete_files($path, $deldir = false)
    {
      $handle = opendir($path);
      if ($handle) {
        while (false !== ( $item = readdir($handle) )) {
          if ($item != "." && $item != "..")
            is_dir("$path/$item") ? delete_files("$path/$item", $deldir) : unlink("$path/$item");
        }
        closedir($handle);
        if ($deldir)
          return rmdir($path);
      } else {
        if (file_exists($path)) {
          return unlink($path);
        return false;
      }
    }
  • 相关阅读:
    自编游戏
    宣言
    Leetcode: 12. Integer to Roman
    Leetcode: 11. Container With Most Water
    Leetcode: 10. Regular Expression Matching
    网络编程:listen函数
    网络编程:connect函数
    Leetcode: 9. Palindrome Number
    Leetcode: 8. String to Integer (atoi)
    Leetcode: 7. Reverse Integer
  • 原文地址:https://www.cnblogs.com/chengfengchi/p/10370378.html
Copyright © 2011-2022 走看看