note 79342 added to function.scandir

From: Date: Wed, 21 Nov 2007 21:39:49 +0000
Subject: note 79342 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-132472@lists.php.net to get a copy of this message
Here's another little function to scan a directory and it's file contents width scandir() including a little file filter.. <?php /** * Recursive function to scan a directory with * scandir() * * * @param String $rootDir * @return multi dimensional array */ function scanDirectories($rootDir) { // set filenames invisible if you want $invisibleFileNames = array(".", "..", ".htaccess", ".htpasswd"); // run through content of root directory $dirContent = scandir($rootDir); $allData = array(); // file counter gets incremented for a better $fileCounter = 0; foreach($dirContent as $key => $content) { // filter all files not accessible $path = $rootDir.'/'.$content; if(!in_array($content, $invisibleFileNames)) { // if content is file & readable, add to array if(is_file($path) && is_readable($path)) { $tmpPathArray = explode("/",$path); // saving filename $allData[$fileCounter]['fileName'] = end($tmpPathArray); // saving while path (for better access) $allData[$fileCounter]['filePath'] = $path; // get file extension $filePartsTmp = explode(".", end($tmpPathArray)); $allData[$fileCounter]['fileExt'] = end($filePartsTmp); // get file date $allData[$fileCounter]['fileDate'] = filectime($path); // get filesize in byte $allData[$fileCounter]['fileSize'] = filesize($path); $fileCounter++; // if content is a directory and readable, add path and name }elseif(is_dir($path) && is_readable($path)) { $dirNameArray = explode('/',$path); $allData[$path]['dirPath'] = $path; $allData[$path]['dirName'] = end($dirNameArray); // recursive callback to open new directory $allData[$path]['content'] = scanDirectories($path); } } } return $allData; } ?> ---- Server IP: 217.13.201.10 Probable Submitter: 88.76.216.0 ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- https://master.php.net/note/edit/79342 Del: integrated -- https://master.php.net/note/delete/79342/integrated Del: useless -- https://master.php.net/note/delete/79342/useless Del: bad code -- https://master.php.net/note/delete/79342/bad+code Del: spam -- https://master.php.net/note/delete/79342/spam Del: non-english -- https://master.php.net/note/delete/79342/non-english Del: in docs -- https://master.php.net/note/delete/79342/in+docs Del: other reasons-- https://master.php.net/note/delete/79342 Reject -- https://master.php.net/note/reject/79342 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132472) next »