note 49825 added to function.scandir

From: Date: Wed, 09 Feb 2005 15:33:23 +0000
Subject: note 49825 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-84721@lists.php.net to get a copy of this message
Ok, in my previous example, you need to do the SORT after you remove the "." and ".." entries from the array. Otherwise, you cannot start using the array at 0. Here is corrected code: <?php function scandir($dir, $no_dots=FALSE) { $files = array(); $dh = @opendir($dir); if ($dh!=FALSE) { while (false !== ($filename = readdir($dh))) { $files[] = $filename; } if ($no_dots) { while(($ix = array_search('.',$files)) > -1) unset($files[$ix]); while(($ix = array_search('..',$files)) > -1) unset($files[$ix]); } sort($files); } return $files; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49825 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49825&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49825&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49825&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49825&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49825&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49825&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84721) next »