Created
August 24, 2012 09:07
-
-
Save glagola/3447864 to your computer and use it in GitHub Desktop.
List Files deeply
This file contains 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 | |
function files($dir, $callback) { | |
$queue = array($dir); | |
$r = -1; | |
$w = 0; | |
while ($r < $w) { | |
$path = $queue[++$r]; | |
$dir = dir($path); | |
while (FALSE !== ($entry = $dir->read())) { | |
if (FALSE !== strstr('..', $entry)) continue; | |
$entry = $path . DIRECTORY_SEPARATOR . $entry; | |
if (is_dir($entry)) { | |
if (is_executable($entry)) { | |
$queue []= $entry; | |
$w++; | |
} | |
} else { | |
$callback($entry); | |
} | |
} | |
$dir->close(); | |
} | |
} | |
files('/etc', function ($file) { | |
echo $file, PHP_EOL; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment