note 91519 added to class.recursiveiteratoriterator

From: Date: Sun, 14 Jun 2009 23:40:42 +0000
Subject: note 91519 added to class.recursiveiteratoriterator
Groups: php.notes 
Request: Send a blank email to php-notes+get-156862@lists.php.net to get a copy of this message
You can use this to quickly find all the files (recursively) in a certain directory. This beats maintaining a stack yourself. <?php $directory = "/tmp/"; $fileSPLObjects = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST ); try { foreach( $fileSPLObjects as $fullFileName => $fileSPLObject ) { print $fullFileName . " " . $fileSPLObject->getFilename() . "\n"; } } catch (UnexpectedValueException $e) { printf("Directory [%s] contained a directory we can not recurse into", $directory); } ?> Note: if there is a directory contained within the directory you are searching in that you have no access to read an UnexpectedValueException will be thrown (leaving you with an empty list). Note: objects returned are SPLFileObjects ---- Server IP: 213.249.64.162 Probable Submitter: 83.161.252.162 ---- Manual Page -- http://www.php.net/manual/en/class.recursiveiteratoriterator.php Edit -- https://master.php.net/note/edit/91519 Del: integrated -- https://master.php.net/note/delete/91519/integrated Del: useless -- https://master.php.net/note/delete/91519/useless Del: bad code -- https://master.php.net/note/delete/91519/bad+code Del: spam -- https://master.php.net/note/delete/91519/spam Del: non-english -- https://master.php.net/note/delete/91519/non-english Del: in docs -- https://master.php.net/note/delete/91519/in+docs Del: other reasons-- https://master.php.net/note/delete/91519 Reject -- https://master.php.net/note/reject/91519 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156862) next »