You are here

function remove_dir in Quiz 6.6

Same name and namespace in other branches
  1. 6.5 includes/moodle_support.php \remove_dir()

Delete directory or only it's content

Parameters

string $dir directory path:

bool $content_only:

Return value

bool success, true also if dir does not exist

1 call to remove_dir()
qformat_qti2::exportprocess in includes/moodle/question/format/qti2/format.php
exports the questions in a question category to the given location

File

includes/moodle_support.php, line 541

Code

function remove_dir($dir, $content_only = false) {
  if (!file_exists($dir)) {

    // nothing to do
    return true;
  }
  $handle = opendir($dir);
  $result = true;
  while (false !== ($item = readdir($handle))) {
    if ($item != '.' && $item != '..') {
      if (is_dir($dir . '/' . $item)) {
        $result = remove_dir($dir . '/' . $item) && $result;
      }
      else {
        $result = unlink($dir . '/' . $item) && $result;
      }
    }
  }
  closedir($handle);
  if ($content_only) {
    return $result;
  }
  return rmdir($dir);

  // if anything left the result will be false, noo need for && $result
}