Created
July 3, 2012 08:00
-
-
Save pwlin/3038377 to your computer and use it in GitHub Desktop.
RecursiveDirectoryIterator
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 | |
// walks a directory recursively | |
// calls at each file $function with the file as argument and $baseArgs as additional arguments | |
function walkRecursivelyDF($dir, $function, $baseArgs) // depth first | |
{ | |
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), | |
RecursiveIteratorIterator::CHILD_FIRST); | |
foreach ($iterator as $path) { | |
if ($path->isDir()) { | |
if (substr($path->__toString(), -2) == '/.') | |
continue; | |
if (substr($path->__toString(), -3) == '/..') | |
continue; | |
} | |
call_user_func_array($function, array($path->__toString(), $baseArgs)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment