note 41432 deleted from function.readdir by tomsommer

From: Date: Fri, 09 Apr 2004 20:59:59 +0000
Subject: note 41432 deleted from function.readdir by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-67924@lists.php.net to get a copy of this message
Note Submitter: php AT grNOSPAMegrobson DOT co DOT uk ---- I often need to process all the files in a given folder (e.g. processing XML files for a web display). This function returns an array giving the paths to all the files in a given folder. I hope someone finds it as useful as I do :) Doing <?php count(dirListAllFiles('./someFolder')) ?> will return the number of files found of course ;) <?php print '<pre>'; function dirListAllFiles($path) { $filesPaths = array(); if ($dirHandle = opendir($path)) { while (false !== ($file = readdir($dirHandle))) { if (is_dir($path . '\\\\' . $file)) { // If it is a valid directory add the files in that directory // to the list (and that will already have all the files in that // due to recursion if ($file != '.' && $file != '..') $filePaths = array_merge($filePaths, dirListAllFiles($path . '\\\\' . $file)); } else $filePaths[] = $path . '\\\\' . $file; } closedir($dirHandle); } return $filePaths; } print_r(dirListAllFiles('./myFolderWithLotsOfFiles')); print '</pre>'; ?>

« previous php.notes (#67924) next »