You are here

function hacked_file_scan_directory in Hacked! 6.2

Same name and namespace in other branches
  1. 8.2 hacked.module \hacked_file_scan_directory()
  2. 5 hacked.module \hacked_file_scan_directory()
  3. 6 hacked.module \hacked_file_scan_directory()
  4. 7.2 hacked.module \hacked_file_scan_directory()

Hacked! version of the core function, can return hidden files too.

See also

file_scan_directory().

1 call to hacked_file_scan_directory()
hackedFileGroup::scan_base_path in includes/hacked_project.inc
Locate all sensible files at the base path of the file group.

File

./hacked.module, line 235
The Hacked! module, shows which project have been changed since download.

Code

function hacked_file_scan_directory($dir, $mask, $nomask = array(
  '.',
  '..',
  'CVS',
), $callback = 0, $recurse = TRUE, $key = 'filename', $min_depth = 0, $depth = 0) {
  $key = in_array($key, array(
    'filename',
    'basename',
    'name',
  )) ? $key : 'filename';
  $files = array();
  if (is_dir($dir) && ($handle = opendir($dir))) {
    while (FALSE !== ($file = readdir($handle))) {
      if (!in_array($file, $nomask)) {
        if (is_dir("{$dir}/{$file}") && $recurse) {

          // Give priority to files in this folder by merging them in after any subdirectory files.
          $files = array_merge(hacked_file_scan_directory("{$dir}/{$file}", $mask, $nomask, $callback, $recurse, $key, $min_depth, $depth + 1), $files);
        }
        elseif ($depth >= $min_depth && preg_match($mask, $file)) {

          // Always use this match over anything already set in $files with the same $$key.
          $filename = "{$dir}/{$file}";
          $basename = basename($file);
          $name = substr($basename, 0, strrpos($basename, '.'));
          $files[${$key}] = new stdClass();
          $files[${$key}]->filename = $filename;
          $files[${$key}]->basename = $basename;
          $files[${$key}]->name = $name;
          if ($callback) {
            $callback($filename);
          }
        }
      }
    }
    closedir($handle);
  }
  return $files;
}