function drush_delete_dir_contents

8.0.x filesystem.inc drush_delete_dir_contents($dir, $force = FALSE)
6.x filesystem.inc drush_delete_dir_contents($dir, $force = FALSE)
7.x filesystem.inc drush_delete_dir_contents($dir, $force = FALSE)
master filesystem.inc drush_delete_dir_contents($dir, $force = FALSE)

Deletes the contents of a directory.

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.

Related topics

2 calls to drush_delete_dir_contents()
drush_core_pre_site_install in commands/core/site_install.drush.inc
Perform setup tasks for installation.
drush_delete_dir in includes/filesystem.inc
Deletes the specified file or directory and everything inside it.

File

includes/filesystem.inc, line 164
Filesystem utilities.

Code

function drush_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, 0777);
    }
    if (!drush_delete_dir($dir . '/' . $item, $force)) {
      return FALSE;
    }
  }
  return TRUE;
}