note 95588 added to function.scandir

From: Date: Mon, 11 Jan 2010 10:36:07 +0000
Subject: note 95588 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-164841@lists.php.net to get a copy of this message
Was looking for a simple way to search for a file/directory using a mask. Here is such a function. By default, this function will keep in memory the scandir() result, to avoid scaning multiple time for the same directory. Requires at least PHP5. function sdir( $path='.', $mask='*', $nocache=0 ){ static $dir = array(); // cache result in memory if ( !isset($dir[$path]) || $nocache) { $dir[$path] = scandir($path); } foreach ($dir[$path] as $i=>$entry) { if ($entry!='.' && $entry!='..' && fnmatch($mask, $entry) ) { $sdir[] = $entry; } } return ($sdir); } ---- Server IP: 195.221.21.36 Probable Submitter: 77.200.231.115 ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- https://master.php.net/note/edit/95588 Del: integrated -- https://master.php.net/note/delete/95588/integrated Del: useless -- https://master.php.net/note/delete/95588/useless Del: bad code -- https://master.php.net/note/delete/95588/bad+code Del: spam -- https://master.php.net/note/delete/95588/spam Del: non-english -- https://master.php.net/note/delete/95588/non-english Del: in docs -- https://master.php.net/note/delete/95588/in+docs Del: other reasons-- https://master.php.net/note/delete/95588 Reject -- https://master.php.net/note/reject/95588 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164841) next »