function drush_find_empty_directories

8.0.x pm.drush.inc drush_find_empty_directories($dir, $exclude = array())
6.x pm.drush.inc drush_find_empty_directories($dir, $exclude = array())
7.x pm.drush.inc drush_find_empty_directories($dir, $exclude = array())
4.x pm.drush.inc drush_find_empty_directories($dir, $exclude = array())
5.x pm.drush.inc drush_find_empty_directories($dir, $exclude = array())
master pm.drush.inc drush_find_empty_directories($dir, $exclude = array())

Return an array of empty directories.

Walk a directory and return an array of subdirectories that are empty. Will return the given directory if it's empty. If a list of items to exclude is provided, subdirectories will be condidered empty even if they include any of the items in the list.

Parameters

string $dir: Path to the directory to work in.

array $exclude: Array of files or directory to exclude in the check.

1 call to drush_find_empty_directories()
pm_update_project in commands/pm/updatecode.pm.inc
Update one project -- a module, theme or Drupal core.

File

commands/pm/pm.drush.inc, line 2574
The drush Project Manager

Code

function drush_find_empty_directories($dir, $exclude = array()) {
  $to_exclude = array_merge(array('.', '..'), $exclude);
  $empty = array();
  $dir_is_empty = TRUE;
  if ($dh = opendir($dir)) {
    while (($file = readdir($dh)) !== FALSE) {
      if (in_array($file, $to_exclude)) {
        continue;
      }
      if (is_dir($dir . '/' . $file)) {
        $subdir = $dir . '/' . $file;
        $subdir_is_empty = TRUE;
        if ($dh2 = opendir($subdir)) {
          while (($file2 = readdir($dh2)) !== FALSE) {
            if (in_array($file2, $to_exclude)) {
              continue;
            }
            $subdir_is_empty = FALSE;
            if (is_dir($subdir . '/' . $file2)) {
              $empty2 = drush_find_empty_directories($subdir . '/' . $file2, $exclude);
              $empty = array_merge($empty, $empty2);
            }
          }
          if ($subdir_is_empty) {
            $empty[] = $subdir . '/' . $file2;
          }
        }
        closedir($dh2);
      }
      $dir_is_empty = FALSE;
    }
  }
  closedir($dh);

  if ($dir_is_empty) {
    return array($dir);
  }

  return $empty;
}