PHP Code
function processEachFileIn($path, callable $callback) {
$objects = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $object) {
if (!$object->isDir() && $object->getFilename() != '.' && $object->getFilename() != '..') {
$callback($object);
}
}
}
Example Usage
The below code demonstrates print all file names in directory /tmp recursively.
processEachFileIn('/tmp', function($file){
echo $file->getFilename()."\n";
});
コメント