function hacked_file_scan_directory in Hacked! 6
Same name and namespace in other branches
- 8.2 hacked.module \hacked_file_scan_directory()
- 5 hacked.module \hacked_file_scan_directory()
- 6.2 hacked.module \hacked_file_scan_directory()
- 7.2 hacked.module \hacked_file_scan_directory()
Hacked! version of the core function, can return hidden files too.
See also
1 call to hacked_file_scan_directory()
- hacked_scan_directory_generate_hashes in ./
hacked.module - Hash the contents of a directory, optionally retrieving from cache.
File
- ./
hacked.module, line 649 - 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;
}