public
Created

RecursiveDirectoryIterator

  • Download Gist
gistfile1.aw
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?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));
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.