note 81597 added to function.scandir

From: Date: Wed, 05 Mar 2008 12:21:39 +0000
Subject: note 81597 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-136763@lists.php.net to get a copy of this message
This is a modification of scanDirectories function that generates a list of all files in the chosen directory and all subdirectories of specific extentions $allowext <?php function scanDirectories($rootDir, $allowext, $allData=array()) { $dirContent = scandir($rootDir); foreach($dirContent as $key => $content) { $path = $rootDir.'/'.$content; $ext = substr($content, strrpos($content, '.') + 1); if(in_array($ext, $allowext)) { if(is_file($path) && is_readable($path)) { $allData[] = $path; }elseif(is_dir($path) && is_readable($path)) { // recursive callback to open new directory $allData = scanDirectories($path, $allData); } } } return $allData; } $rootDir = "www"; $allowext = array("zip","rar","html"); $files_array = scanDirectories($rootDir,$allowext); print_r($files_array); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 196.218.239.217 ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- https://master.php.net/note/edit/81597 Del: integrated -- https://master.php.net/note/delete/81597/integrated Del: useless -- https://master.php.net/note/delete/81597/useless Del: bad code -- https://master.php.net/note/delete/81597/bad+code Del: spam -- https://master.php.net/note/delete/81597/spam Del: non-english -- https://master.php.net/note/delete/81597/non-english Del: in docs -- https://master.php.net/note/delete/81597/in+docs Del: other reasons-- https://master.php.net/note/delete/81597 Reject -- https://master.php.net/note/reject/81597 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136763) next »