You are here

function hacked_file_scan_directory in Hacked! 8.2

Same name and namespace in other branches
  1. 5 hacked.module \hacked_file_scan_directory()
  2. 6.2 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.

Parameters

$dir:

$mask:

array $nomask:

int $callback:

bool|TRUE $recurse:

string $key:

int $min_depth:

int $depth:

Return value

array

See also

file_scan_directory().

2 calls to hacked_file_scan_directory()
hackedFileGroup::scan_base_path in src/hackedFileGroup.php
Locate all sensible files at the base path of the file group.
hackedProjectWebFilesDownloader::download in src/hackedProjectWebFilesDownloader.php
Download the remote files to the local filesystem.

File

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

Code

function hacked_file_scan_directory($dir, $mask, $nomask = [
  '.',
  '..',
  'CVS',
], $callback = 0, $recurse = TRUE, $key = 'filename', $min_depth = 0, $depth = 0) {
  $key = in_array($key, [
    'filename',
    'basename',
    'name',
  ]) ? $key : 'filename';
  $files = [];
  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 (is_callable($callback)) {
            $callback($filename);
          }
        }
      }
    }
    closedir($handle);
  }
  return $files;
}