Last active
January 27, 2020 15:54
-
-
Save davidmz/5181134 to your computer and use it in GitHub Desktop.
Рекурсивный перебор файлов по заданной glob-маске.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Рекурсивный проход по каталогу | |
* @return array Полный список найденных файлов | |
*/ | |
function recursiveGlob($startDir, $fileMask) { | |
$found = glob($startDir.DIRECTORY_SEPARATOR.$fileMask); | |
$dirs = glob($startDir.DIRECTORY_SEPARATOR."*", GLOB_ONLYDIR); | |
foreach ($dirs as $dir) $found = array_merge($found, recursiveGlob($dir, $fileMask)); | |
return $found; | |
} | |
/** | |
* Рекурсивный проход по каталогу с вызовом $callback на каждом файле | |
*/ | |
function globWalk($startDir, $fileMask, $callback) { | |
$found = glob($startDir.DIRECTORY_SEPARATOR.$fileMask); | |
foreach ($found as $path) $callback($path); | |
$dirs = glob($startDir.DIRECTORY_SEPARATOR."*", GLOB_ONLYDIR); | |
foreach ($dirs as $dir) globWalk($dir, $fileMask, $callback); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment