You are here

function boost_tree_directory in Boost 6

Return a tree directory structure array

Parameters

$dir: Directory name

$limit: If there are more then this many sub directories in this directory then set the $GLOBALS['_boost_dir_limit_hit'] variable. Default is 31,000; set to zero to disable this functionality.

1 call to boost_tree_directory()
boost_requirements in ./boost.install
Implementation of hook_requirements().

File

./boost.install, line 391
Handles Boost module installation and upgrade tasks.

Code

function boost_tree_directory($dir, $limit = 31000) {
  if (!is_dir($dir)) {
    return FALSE;
  }

  // Get directories/files
  $files = scandir($dir);

  // Only keep directories
  $dirs = array();
  foreach ($files as $file) {
    if (is_dir($dir . '/' . $file) && $file != '.' && $file != '..') {
      $dirs[] = $file;
    }
  }

  // Recursive operation to get subdirectories
  if (count($dirs)) {
    if (count($dirs) >= 31990) {
      $GLOBALS['_boost_dir_limit_hit'][] = $dir;
    }
    elseif ($limit && count($dirs) > $limit) {
      $GLOBALS['_boost_dir_limit_warning'][] = $dir;
    }
    foreach ($dirs as $key => $subdir) {
      unset($dirs[$key]);
      $dirs[$subdir] = boost_tree_directory($dir . '/' . $subdir, $limit);
    }
  }
  else {
    return NULL;
  }

  // Return Array
  return $dirs;
}