function delete_dir

3.x pm.drush.inc delete_dir($dir)

Deletes a directory, all files in it and all subdirectories in it (recursively). Use with care! Written by Andreas Kalsch

File

commands/pm/pm.drush.inc, line 962
The drush Package Manager

Code

function delete_dir($dir) {
  if (substr($dir, strlen($dir) -1, 1) != '/') {
    $dir .= '/';
  }

  if ($handle = opendir($dir)) {
    while ($obj = readdir($handle)) {
      if ($obj != '.' && $obj != '..') {
        if (is_dir($dir . $obj)) {
          if (!delete_dir($dir . $obj)) {
            return false;
          }
        }
        elseif (is_file($dir . $obj)) {
          if (!unlink($dir . $obj)) {
            return false;
          }
        }
      }
    }

    closedir($handle);

    if (!@rmdir($dir)) {
    }
    return true;
  }
  return false;
}