function unish_delete_dir_contents

8.0.x bootstrap.inc unish_delete_dir_contents($dir, $force = FALSE)
6.x drush_testcase.inc unish_delete_dir_contents($dir, $force = FALSE)
7.x bootstrap.inc unish_delete_dir_contents($dir, $force = FALSE)
master bootstrap.inc unish_delete_dir_contents($dir, $force = FALSE)

Deletes the contents of a directory.

This is essentially a copy of drush_delete_dir_contents().

Parameters

string $dir: The directory to delete.

bool $force: Whether or not to try everything possible to delete the contents, even if they're read-only. Defaults to FALSE.

Return value

bool FALSE on failure, TRUE if everything was deleted.

See also

drush_delete_dir_contents()

1 call to unish_delete_dir_contents()
unish_file_delete_recursive in tests/bootstrap.inc
Deletes the specified file or directory and everything inside it.

File

tests/bootstrap.inc, line 153
Initialize a sandboxed environment. Starts with call unish_init() at bottom.

Code

function unish_delete_dir_contents($dir, $force = FALSE) {
  $scandir = @scandir($dir);
  if (!is_array($scandir)) {
    return FALSE;
  }

  foreach ($scandir as $item) {
    if ($item == '.' || $item == '..') {
      continue;
    }
    if ($force) {
      @chmod($dir, );
    }
    if (!unish_file_delete_recursive($dir . '/' . $item, $force)) {
      return FALSE;
    }
  }
  return TRUE;
}