-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.glob_recursive.php
More file actions
31 lines (30 loc) · 870 Bytes
/
function.glob_recursive.php
File metadata and controls
31 lines (30 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
//// Glob Recursive Function
// Glob Recursively to a Pattern
function glob_recursive($Pattern, $Flags = 0, $Strip_Underscore = false) {
$Return = array();
// Search in the Current Directory
foreach ( glob($Pattern, $Flags) as $File) {
if (
!$Strip_Underscore ||
strpos($File, '/_') === false
) {
$Return[] = realpath($File);
}
}
// FOREACHDIRECTORY
// Search in ALL sub-directories.
foreach ( glob(dirname($Pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) as $Directory ) {
// This is a recursive function.
// Usually, THIS IS VERY BAD.
// For searching recursively however,
// it does make some sense.
if (
!$Strip_Underscore ||
strpos($Directory, '/_') === false
) {
$Return = array_merge($Return, glob_recursive($Directory.'/'.basename($Pattern), $Flags, $Strip_Underscore));
}
} // FOREACHDIRECTORY
return $Return;
}